Saving Fragment state in ViewPager

前端 未结 6 1399
旧巷少年郎
旧巷少年郎 2020-12-04 15:25

I tried out the sample code from the API and it didn\'t really work so I implemented my own:

FragmentPagerSupport

public class Fragm         


        
6条回答
  •  佛祖请我去吃肉
    2020-12-04 16:04

    Update: In the getItem of MyAdapter you return a new instance of your Fragment. Android will not call getItem on every swipe. It will only call getItem to get a new instance, but will reuse the existing instances as long as they are availible.

    About the state part of the Demo. I can't help you. I think the normal techniques for restoring state in Fragements/Activities apply here, so nothing special when loading it in a ViewPager (but I might be wrong).

提交回复
热议问题