What is the difference between FragmentPagerAdapter and FragmentStatePagerAdapter?

后端 未结 7 2043
傲寒
傲寒 2020-11-22 12:31

What is the difference between FragmentPagerAdapter and FragmentStatePagerAdapter?

About FragmentPagerAdapter Google\'s guide

7条回答
  •  南笙
    南笙 (楼主)
    2020-11-22 13:14

    Something that is not explicitly said in the documentation or in the answers on this page (even though implied by @Naruto), is that FragmentPagerAdapter will not update the Fragments if the data in the Fragment changes because it keeps the Fragment in memory.

    So even if you have a limited number of Fragments to display, if you want to be able to refresh your fragments (say for example you re-run the query to update the listView in the Fragment), you need to use FragmentStatePagerAdapter.

    My whole point here is that the number of Fragments and whether or not they are similar is not always the key aspect to consider. Whether or not your fragments are dynamic is also key.

提交回复
热议问题