Replace Fragment inside a ViewPager

后端 未结 18 1366
别那么骄傲
别那么骄傲 2020-11-22 00:26

I\'m trying to use Fragment with a ViewPager using the FragmentPagerAdapter. What I\'m looking for to achieve is to replace a fragment, positioned

18条回答
  •  臣服心动
    2020-11-22 01:09

    In your onCreateView method, container is actually a ViewPager instance.

    So, just calling

    ViewPager vpViewPager = (ViewPager) container;
    vpViewPager.setCurrentItem(1);
    

    will change current fragment in your ViewPager.

提交回复
热议问题