开发者

Adding a Fragment with add() method doesn't hide previous fragments

开发者 https://www.devze.com 2023-03-10 10:00 出处:网络
I\'m experiencing \"unexpected behaviour\" when using add() method to add a new fragment. I want to add a new fragment on a FrameLayout, but when I do it the previous fragment stills visible.

I'm experiencing "unexpected behaviour" when using add() method to add a new fragment.

I want to add a new fragment on a FrameLayout, but when I do it the previous fragment stills visible.

  • Is this the expected result when using add() method?

  • It is because I am using a FrameLayout and add() method just place a fragment over the FrameLayou开发者_运维知识库t without affect the previous one?

Thx


Not a bug. Try replace(..). instead adding to the back stack if required.

EDIT I think that using replace or remove() add() will solve your problem but as you highlight in your related post there is a bug which manifests itself under your particular set of circumstances.


Other simple thing what you can do is to call

FragmentTransaction t = getFragmentManager.beginTransaction();
t.hide(<your_fragment>);
t.add(<container, <new_fragment>);
..do the rest here..
t.commit();

Let me know if this helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号