Android: Viewpager and FragmentStatePageAdapter

后端 未结 5 1184
春和景丽
春和景丽 2021-02-04 15:05

I\'m designing an app that allows users to flip between multiple pages in a ViewPager. I\'ve been struggling trying to figure out how it is possible to remove a Fragment instan

5条回答
  •  孤城傲影
    2021-02-04 15:36

    Looking at the various documentation pieces, my best guess is that the views you are creating do not have an ID attached to them. Assuming that the fragment's saved state is created from Fragment.onSaveInstanceState, then the fragment will automatically save any view's state that has an id. You probably have a default id associated with your ListView/GridView if you created them from a layout file. You can also associate an id with the views by calling setId.

    Also, for your custom filled fragment, you may also have to do something custom in onSaveInstanceState.

提交回复
热议问题