Replace fragment with another fragment inside ViewPager

后端 未结 5 624
生来不讨喜
生来不讨喜 2020-12-01 03:36

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

[Fragment1][Fragment2][Fragment3]

What I\'m t

5条回答
  •  囚心锁ツ
    2020-12-01 04:39

    Try using FragmentStatePagerAdapter

    http://android-developers.blogspot.com/2011_08_01_archive.html

    coz it will remove the fragment as you swipe through the view(also when you call getitem), so you don't need to explicitly remove them yourself.

    I've been having the same problem it works for me.

    I try your code and remove the if (fragment!=null) block and it works.

提交回复
热议问题