سؤال

I have two fragments in a single container (say A and B) added in a single transaction. I try to replace them with C. According to the documentation, replace should remove all fragments from a specified container and then add new one. Instead, it replaces only first one. So I end up with B and C fragments. This confuses me a lot. Is it a bug or what?

I already know that adding several fragments to single container is considered bad practice. But I'm curious anyway.

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

هل كانت مفيدة؟

المحلول

I guess you do like this:

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();

And then just add new fragment.

getSupportFragmentManager().beginTransaction().add(R.id.container, fragmentC).commit();
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top