4

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

4

1 回答 1

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();
于 2013-10-14T19:58:05.060 回答