简体   繁体   English

用另一个片段替换ViewPager

[英]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. ViewPagerFragments之一中,我有一个项目列表。 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 . 但它仅替换项目列表所在的ViewPagerFragmentViewPager替换代表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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM