Update ViewPager dynamically?

后端 未结 20 3082
时光说笑
时光说笑 2020-11-22 02:00

I can\'t update the content in ViewPager.

What is the correct usage of methods instantiateItem() and getItem() in FragmentPagerAdapter class?

I was using onl

20条回答
  •  北恋
    北恋 (楼主)
    2020-11-22 02:42

    Use FragmentStatePagerAdapter instead of FragmentPagerAdapter if you want to recreate or reload fragment on index basis For example if you want to reload fragment other than FirstFragment, you can check instance and return position like this

     public int getItemPosition(Object item) {
        if(item instanceof FirstFragment){
           return 0;
        }
        return POSITION_NONE;
     }
    

提交回复
热议问题