When is FragmentPagerAdapter's getItem called?

前端 未结 3 1549
陌清茗
陌清茗 2020-12-07 22:30

I\'m writing an application that uses the FragmentPagerAdapter. The fragments in the adapter need to be updated according to outside data - but that doesn\'t happen. I notic

3条回答
  •  有刺的猬
    2020-12-07 23:26

    Simply use FragmentStatePagerAdapter instead of FragmentPagerAdapter

    FragmentStatePagerAdapter destroys the instance of unneeded instance of fragments and instantiates again on-demand basis. On the other hand, FragmentPagerAdapter just detach the Fragment and reattach it. So fragments created in FragmentPagerAdapter never get destroyed. That's why I always prefer FragmentStatePagerAdapter.

提交回复
热议问题