previous片段的新片段在可见光 [英] Previous fragment visible under the new fragment

查看:129
本文介绍了previous片段的新片段在可见光的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个标签+ ViewPager 布局,并在其中一个选项卡我有一个列表视图。当我更换后的onclick该列表中的片段我仍然可以看到新片段上有老下片段。参见:

I have a tab + ViewPager layout and in one of these tabs I have a list view. When I replace that list fragment upon the onclick I can still see the old fragment under the new fragment. See:

code:

FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction transaction = fragmentManager.beginTransaction();
HallsInStateFragment hallsForState = new HallsInStateFragment();        
transaction.replace(R.id.container, hallsForState);
transaction.addToBackStack(null);
transaction.commit();

其中 R.id.container 是的FrameLayout在视图中。

where the R.id.container is the FrameLayout in the view.

推荐答案

而不是R.id.container把片段像这样的ID:((ViewGroup中)getView()的getParent()。)。的getId()。其实这是不更换片段,但previous布局即的FrameLayout。这对我的作品,我希望它会在你的工作的情况下也。

Instead of R.id.container put id of fragment like this: ((ViewGroup)getView().getParent()).getId(). Actually it is not replacing the fragment but the previous layout i.e FrameLayout. It works for me and i hope it will work in your case also.

这篇关于previous片段的新片段在可见光的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆