Navigating back to FragmentPagerAdapter -> fragments are empty

后端 未结 5 698
庸人自扰
庸人自扰 2020-12-04 11:23

I have a Fragment (I\'ll call it pagerFragment) that is added to the backstack and is visible. It holds a viewPager with a FragmentPagerAdapt

5条回答
  •  旧巷少年郎
    2020-12-04 11:58

    I had the same problem. The solution for me was simple:

    in onCreateView I had:

    // Create the adapter that will return a fragment for each of the three
    // primary sections of the app.
    mSectionsPagerAdapter = new SectionsPagerAdapter(getActivity()
        .getSupportFragmentManager());
    

    where SectionPageAdapter is something like this:

    class SectionsPagerAdapter extends FragmentPagerAdapter {
    ...
    }
    

    after changing getSupportFragmentManager to

    mSectionsPagerAdapter = new SectionsPagerAdapter(getChildFragmentManager());
    

    it started working! Hope this helps.

提交回复
热议问题