FragmentPagerAdapter is not removing items (Fragments) correctly

前端 未结 9 1201
别跟我提以往
别跟我提以往 2021-01-30 01:30

I have implemented the FragmentPagerAdapter and and using a List to hold all fragments for my ViewPager to display. On

9条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-30 02:28

    I have been having this same issue until I dawned on me, I was creating my PagerView from within another Fragment and not the main activity.

    My solution was to pass the ChildFragment Manager into the constructor of the Fragment(State)PagerAdapter and not the Fragment Manager of the parent Fragment.

    Using the ChildFragmentManager all the Fragments created by the ViewPagerAdapter are cleaned up automatically when the parent Fragment is destroyed.

提交回复
热议问题