FragmentTransaction.replace replaces only the first fragment in the container

I have two fragments in one container (e.g. A and B) added to one transaction. I am trying to replace them with C. According to the documentation, replace should remove all fragments from the specified container, and then add a new one. Instead, it replaces only the first. So I end up with fragments B and C. It bothers me. Is this a mistake or what?

I already know that adding multiple fragments to the same container is considered bad practice. But I'm still interested.

UPDATE: earlier: http://code.google.com/p/android/issues/detail?id=28452

+4
source share
1

, :

Fragment fragmentA = (getFragmentManager().findFragmentById(R.id.fragmentC));
     Fragment fragmentB = (getFragmentManager().findFragmentById(R.id.fragmentB));
     FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();

         ft.remove(fragmentA);
            ft.remove(fragmentB);
            ft.commit();

.

getSupportFragmentManager().beginTransaction().add(R.id.container, fragmentC).commit();
+1

All Articles