android - Change Fragment dynamic -


i have 2 questions. first, can me someone, why not works? try change fragment, nothing. see first fragment.

mainactivity:

... if (savedinstancestate == null) {         fm.begintransaction()                 .add(r.id.firstfragment, new firstfragment()).commit();      }      findviewbyid(r.id.button1).setonclicklistener(new onclicklistener() {         @override         public void onclick(view v) {             switchfragment(r.id.firstfragment, new firstfragment());         }     });      findviewbyid(r.id.button2).setonclicklistener(new onclicklistener() {         @override         public void onclick(view v) {             switchfragment(r.id.secondfragment, new secondfragment());         }     });  }  private void switchfragment(int fragid, fragment frag){      fragmenttransaction ft = getsupportfragmentmanager().begintransaction();      ft.replace(fragid, frag);      ft.commit(); } 

fragments in main.xml:

<fragment     android:id="@+id/firstfragment"     android:name="com.example.firstfragment"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:layout_above="@+id/view01"     android:layout_below="@+id/view1" /> 

fragmentclass have this:

    @override   public view oncreateview(layoutinflater inflater, viewgroup container,       bundle savedinstancestate) {     view view = inflater.inflate(r.layout.fragment_clublist, container, false);      return view;   } 

and fragment this:

<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" >  <textview     android:id="@+id/textview1"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:text="fragment1"     android:textappearance="?android:attr/textappearancelarge"      android:textcolor="#ffff0000"/> 

i don't know, why not change fragment. check, switchfragment calling true.

second question is: way change fragments? is, if have 10 fragments?

thanks help! :)

int fragid 

should id of container hosts fragment, not id of fragment itself


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -