[android-developers] Re: replacing a fragments not working
I can remove and add fragments, but replace doesn't cause the new Fragment to show up. The API docs are a little unclear about which existing Fragment would be replaced. On Mar 23, 4:49 pm, jotobjects jotobje...@gmail.com wrote: 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
Re: [android-developers] Re: replacing a fragments not working
Many of the API demos use this -- for example the stack and layout demos. You can look at those and see what you are doing differently. On Thu, Mar 24, 2011 at 10:37 AM, jotobjects jotobje...@gmail.com wrote: I can remove and add fragments, but replace doesn't cause the new Fragment to show up. The API docs are a little unclear about which existing Fragment would be replaced. On Mar 23, 4:49 pm, jotobjects jotobje...@gmail.com wrote: 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 -- Dianne Hackborn Android framework engineer hack...@android.com Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails. All such questions should be posted on public forums, where I and others can see and answer them. -- 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
[android-developers] Re: replacing a fragments not working
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
[android-developers] Re: replacing a fragments not working
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 jotobje...@gmail.com 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 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