How to get the instance of the currently visible fragment in ViewPager:

后端 未结 3 1471
一生所求
一生所求 2021-01-06 23:28

I\'m building an application that shows different fragments in a ViewPager. I add these fragments to the ViewPager like this:

 publ         


        
3条回答
  •  轮回少年
    2021-01-06 23:56

    You can get the Current Visible Fragment using viewpager.getCurrentItem() method in the following way:

    Fragment fr = getSupportFragmentManager().findFragmentByTag("android:switcher:" + R.id.pager + ":" + mViewPager.getCurrentItem());
    

提交回复
热议问题