Retrieve a Fragment from a ViewPager

前端 未结 23 2569
逝去的感伤
逝去的感伤 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:46

    Fragment yourFragment = yourviewpageradapter.getItem(int index);
    

    index is the place of fragment in adapter like you added fragment1 first so retreive fragment1 pass index as 0 and so on for rest

提交回复
热议问题