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 <g.king....@gmail.com> wrote:
> Try to use framelayout...
>
> 2011/3/24 jotobjects <jotobje...@gmail.com>
>
>
>
> > 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 android-developers@googlegroups.com
> > To unsubscribe from this group, send email to
> > android-developers+unsubscr...@googlegroups.com
> > 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 android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to