I\'m developing an app with a ViewPager for lateral scrolling tables, sometimes i need to change the adapter to load a different set of tables. I\'ve tried to do the following:<
I see that @RRTW way worked for some people but it did not do the trick for me (although it was close). Without commitNow()
instead of regular commit()
it would not work properly. I did something like that:
private fun changePagerAdapter(newAdapter: PagerAdapter) {
val transaction = supportFragmentManager.beginTransaction()
supportFragmentManager.fragments.forEach {
transaction.remove(it)
}
transaction.commitNow()
view_pager.adapter = newAdapter
}