我的viewpager2没有重复加载页面。
适配器:
class ViewPager2Adapter(fragmentManager: FragmentManager, lifecycle: Lifecycle): FragmentStateAdapter(fragmentManager, lifecycle) {
var fragments = arrayListOf(
OneFragment(),
TwoFragment(),
ThreeFragment(),
FourFragment(),
FiveFragment(),
SixFragment(),
SevenFragment(),
EightFragment()
)
override fun getItemCount(): Int {
return fragments.size
}
override fun createFragment(position: Int): Fragment {
return fragments[position]
}
}
ViewPager2选项:
val adapter = ViewPager2Adapter(childFragmentManager, lifecycle)
adapter.notifyDataSetChanged()
viewpager.adapter = adapter
viewpager.orientation = ViewPager2.ORIENTATION_HORIZONTAL
在旧的viewpager片段上反复加载