替换ViewPagerAdapter中的Fragment

时间:2016-02-29 14:54:13

标签: android android-viewpager

它是ViewPager, ViewPagerAdapter,TabLayoutFagment1, Fragment2, Fragment3ViewPager显示2个片段。

ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
ViewPagerAdapter mVPAdapter = new ViewPagerAdapter(getSupportFragmentManager());
mVPAdapter.addFrag(new Fragment_1(), "");
mVPAdapter.addFrag(new Fragment_2(), "");
viewPager.setAdapter(mVPAdapter); 
tabLayout = (TabLayout) findViewById(R.id.tabs);
tabLayout.setupWithViewPager(viewPager);

我可以使用Fragment1替换Fragment3上的ViewPagerAdapter吗?

1 个答案:

答案 0 :(得分:0)

试试这个

$queno

在attachfragment中,您将从fragment3替换fragment1。你可以使用boolean varible将该片段添加到backstack中

 Fragment fragment_name = new Fragment_3();
 attachFragment(childFragment, Constant.TAG_FRAGMENT3, true);