Refresh fragment in a view pager within another fragment

I have checked several questions here about updating fragments in a ViewPager but none are within another fragment. Still I tried the solutions both in the main fragment and the internal ones and none worked.

I'm using Xamarin Android and I have an activity with a BottomNavigationView to switch between 5 different Fragments.

On my first fragment I have a ViewPager with 4 tabs (so 4 fragments). Each of these internal fragments has a ListView.

When the page loads it all works, fragment appears with the ViewPager and the populated list. I switch between the pages and all the lists are there and fine.

If I switch to another fragment using the Bottom Navigation and come back then I see the ViewPager meaning I see the tabs but the Listview in the first internal fragment is gone/empty. I switch to the second tab, usually it'll be empty too but if I switch to the 3rd then that one is usually populated and the 4th too and if I switch back to 2 and then 1 they usually get populated.

How can I refresh the internal fragment/Listview when switching between the external fragments/Bottom Navigation?

1 answer

  • answered 2018-09-24 15:07 newbieCoder.pkg

    Change your viewPagerAdapter to getChildFragmentManager() instead of getFragmentManager()

    ViewPagerAdapter adapter = new ViewPagerAdapter(getChildFragmentManager());