0

I am creating a Tabbed Activity in my Android app. For this, I have this fragment_main.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.obware.story.Activitys.MainActivity$MainFragment">



<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/main_scrollview">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/main_linear_layout"
        android:orientation="horizontal">
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/thisid"
            android:text="HI"/>
    </LinearLayout>
</ScrollView>

And this to add it:

 public static class MainFragment extends Fragment{

    public MainFragment(){

    }

    public static MainFragment newInstance(){
        MainFragment fragment = new MainFragment();
        Bundle args = new Bundle();
        fragment.setArguments(args);
        return fragment;
    }

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle saveInstanceState){
        View mainView = inflater.inflate(R.layout.fragment_main, container, false);
        return mainView;
    }



}

Now I want to add just some text to test it, but it doesn't work. Here I add it:

public void loadContent(){
    LinearLayout layout = (LinearLayout)findViewById(R.id.main_linear_layout);
    TextView test = new TextView(this);
    test.setText("TEST");
    test.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT));
    layout.addView(test);
    //Here I tested if I can access it. The layout dissappears, so yes, I can access it.
    //layout.setVisibility(View.GONE);

}

So, does anyone know what's the error? (I have also tried to add components with xml files. Doesn't work either) Thanks!

user6586661
  • 432
  • 1
  • 11
  • 24

0 Answers0