All the examples of replace() have one Fragment inside one FrameLayout. This arrangement of one Container ViewGroup per Fragment seems to be necessary for dynamically replacing Fragments.
On Mar 24, 4:32 pm, jotobjects <[email protected]> wrote: > We did switch to using FrameLayout for other reasons (have not tried > replace() with that yet). LinearLayout works if you want to add and > remove the last View in the LinearLayout. > > FragmentTransaction.replace() is used in samples in these files - > - FragmentsStack.java > - Fragments.Layout.java > - FragmentPreferences.java > > Thanks for the tips > > On Mar 23, 6:35 pm, King Sun <[email protected]> wrote: > > > > > Try to use framelayout... > > > 2011/3/24 jotobjects <[email protected]> > > > > Having a bit of a go with Fragments and hitting a snag. My layout > > > looks like this. The objective is to add a Fragment to the > > > LinearLayout. > > > > <LinearLayout xmlns:android="http://schemas.android.com/apk/res/ > > > android" > > > android:id="@+id/foobar" > > > android:layout_width="fill_parent" > > > android:layout_height="wrap_content" > > > android:orientation="vertical" > > > /> > > > > First I do this - which works fine to add and display the Fragment > > > into the layout container > > > > Fragment f1 = new FragmentOne(); > > > fragmentManager.beginTransaction().add(R.id.foobar, f1, > > > "ABC").commit(); > > > > later on I want to replace that Fragment with a different one so I do > > > this - > > > > Fragment f2 = new FragmentTwo(); > > > fragmentManager.beginTransaction().replace(R.id.foobar, f2, > > > "DEF").commit(); > > > > But Fragment f1 is still there in the View. What part of this is am I > > > doing incorrectly? > > > > -- > > > You received this message because you are subscribed to the Google > > > Groups "Android Developers" group. > > > To post to this group, send email to [email protected] > > > To unsubscribe from this group, send email to > > > [email protected] > > > For more options, visit this group at > > >http://groups.google.com/group/android-developers?hl=en -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

