Retrieve a Fragment from a ViewPager

前端 未结 23 2536
逝去的感伤
逝去的感伤 2020-11-21 11:13

I\'m using a ViewPager together with a FragmentStatePagerAdapter to host three different fragments:

  • [Fragment1]
  • [Fragment2]<
23条回答
  •  长发绾君心
    2020-11-21 11:41

    For my case, none of the above solutions worked.

    However since I am using the Child Fragment Manager in a Fragment, the following was used:

    Fragment f = getChildFragmentManager().getFragments().get(viewPager.getCurrentItem());

    This will only work if your fragments in the Manager correspond to the viewpager item.

提交回复
热议问题