Reputation: 5177
I have a FragmentActivity that contains a FrameLayout. I use the following code to add Fragments to the Fragment Activity.
FragmentManager fm = getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.add(R.id.fragment_content, fragment, fargmentTag);
ft.addToBackStack(null);
ft.commit();
Now R.id.fragment_content is FrameLayout. This adds a Fragment onto the view. But the underlying view still remains visible. Meaning the one lying view is seen through the new fragment ? What am i doing wrong.
Kind Regards
Upvotes: 1
Views: 2724
Reputation: 61
Using ft.replace will replace any previously added fragment with this fragment but if the activity has some view added to its layout rather than a fragment ,then the fragment added through add or replace will show its content over it rather than replacing it as it is not a fragment. either add another layout within your main layout and assign it some id and then add the fragment to that container. Hope it helps.
Upvotes: 0
Reputation: 73
ft.replace() should work fine, otherwise you have to update your question for a better understanding.
Upvotes: 1
Reputation: 485
for the next fragment use ft.replace();
so the previous one will be repalced.
Upvotes: 1
Reputation: 152917
Either ft.remove()
the old fragment, or use ft.replace()
instead of ft.add()
.
Upvotes: 1