Multiple Tab fragments inside bottom navigation fragment

后端 未结 2 1735
旧巷少年郎
旧巷少年郎 2020-12-23 18:33

In bottom navigation with three tabs (Home, Dashboard, Notifications). Each bottom navigation tab is a fragment. The first tab ie. Home fragment contains another top navigat

相关标签:
2条回答
  • 2020-12-23 18:56

    Try use getChildFragmentManager() instance of getSupportFragmentManager().

    0 讨论(0)
  • 2020-12-23 19:05

    Actually, it is a common mistake - you're using FragmentManager of your Activity inside the fragment, but since this fragment contains another child fragments you have to use FragmentManager of the fragment itself. So the fix is simple - you just have to change getActivity().getSupportFragmentManager() to getChildFragmentManager() inside your fragments, so the code will be:

    private void setupViewPager(ViewPager viewPager) {
        TabViewPagerAdapter adapter = new TabViewPagerAdapter(getChildFragmentManager());
        ...
        ...
        viewPager.setAdapter(adapter);
    }
    

    And this should work as expected.

    0 讨论(0)
提交回复
热议问题