When is FragmentPagerAdapter's getItem called?

前端 未结 3 1567
陌清茗
陌清茗 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:12

    getItem will be called whenever the adapter needs a fragment and the fragment does not exist.

    If the fragment already exists in the FragmentManager then there is no need to instantiate it and getItem does not need to be called.

    To update an existing fragment you would need to retrieve it from the FragmentManager or the adapter and manipulate it accordingly.

    By default, the viewpager will create fragments for the visible page and the one next to it. I.e to start with, fragments in position 1 and 2. When you swipe to page 2, the fragment at position 3 will be created etc

提交回复
热议问题