4

I'm making a simple application to understand Fragments in android. Everything seems simple, except one i.e. I added multiple fragments dynamcially in a LeniarLayout. It worked fine, but now when I try to call replace on that container layout with some other fragment , it doesn't removes all the previously added fragments. Why such kind of behaviour ?

Android api says "Replace an existing fragment that was added to a container. This is essentially the same as calling remove(Fragment) for all currently added fragments that were added with the same containerViewId and then add(int, Fragment, String) with the same arguments given here."

Please guide me.

SAMD
  • 421
  • 1
  • 3
  • 7

1 Answers1

0

Maybe you have forgoten to do a commit?

this is the full flow to work:

final FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.content_fragment, myFragment, myFragment.name );
transaction.commit();

Hope this helps.

Sulfkain
  • 5,082
  • 1
  • 20
  • 38