I have three Fragment
s
work with ViewPager2 and TabLayout set smoothScroll true use defalut, but lazy loading not working
TabLayoutMediator(tabLayout, viewPager) {
tab, position ->
tab.text = position.toString()
}.attach()
and what I need is
I need smoothScroll the tab Indicator
Lazy loading Fragment when I scroll the page or Select Tab the Fragment data load view show
tabLayout.addOnTabSelectedListener(object: TabLayout.OnTabSelectedListener{
override fun onTabSelected(tab: TabLayout.Tab?) {
tab?:return
viewPager.setCurrentItem(tab.position, false)
}
override fun onTabUnselected(tab: TabLayout.Tab?) {
}
override fun onTabReselected(tab: TabLayout.Tab?) {
}
})
the most important code is viewPager.setCurrentItem(tab.position, false)
to override TabLayoutMediator addOnTabSelectedListener, so that it can be smooth scroll but also can lazy load