[英]Replace ViewPager with another Fragment
I have a Fragment
which contains a ViewPager
which contains two Fragment
s. 我有一个
Fragment
,其中包含一个ViewPager
,其中包含两个Fragment
。 In one of the ViewPager
's Fragments
I have a list of items. 在
ViewPager
的Fragments
之一中,我有一个项目列表。 When I click on the item, I want the whole Fragment
containing the ViewPager
to be replaced with a new Fragment
which represents details about the item that was clicked (similar to starting a new Activity
which replaces the existing one). 当我单击该项目时,我希望将包含
ViewPager
的整个Fragment
替换为一个新的Fragment
,它代表有关所单击项目的详细信息(类似于启动一个新的Activity
来替换现有的Activity
)。 I do like this: 我喜欢这样:
CustomFragment fragment = new CustomFragment();
FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.container, fragment);
transaction.addToBackStack(null);
transaction.commit();
but it only replaces the Fragment
of the ViewPager
where the list of items is, not the whole Fragment
that represents the ViewPager
. 但它仅替换项目列表所在的
ViewPager
的Fragment
, ViewPager
替换代表ViewPager
的整个Fragment
。 How to achieve that the whole ViewPager
Fragment
would be replaced, not its child Fragment
? 如何实现整个
ViewPager
Fragment
而不是其子Fragment
替换?
您需要获得对包含选项卡的整个容器的FragmentActivity
的引用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.