Getting the current Fragment instance in the viewpager

前端 未结 30 2642
醉话见心
醉话见心 2020-11-22 08:56

Below is my code which has 3 Fragment classes each embedded with each of the 3 tabs on ViewPager. I have a menu option. As shown in the onOpt

30条回答
  •  天命终不由人
    2020-11-22 09:07

    FragmentStatePagerAdapter has public method with the name instantiateItem that return your fragment based on specified parameter values, this method has two parameters ViewGroup (ViewPager) and position.

    public Object instantiateItem(ViewGroup container, int position);
    

    Used this method to get specified position's fragment,

    Fragment fragment = (Fragment) adaper.instantiateItem(mViewPager, position);
    

提交回复
热议问题