我正在使用带有 FragmentStateAdapter 的 ViewPager2,我正在调用 notifyItemChanged(position)。但正如预期的那样 createFragment 方法不会再次调用。这是预期的行为还是错误,我该怎么办
我的代码是
class EEditionPagerAdapter(
fragmentManager: FragmentManager, lifecycle: Lifecycle, private var date: String
) : FragmentStateAdapter(fragmentManager, lifecycle) {
private var menuList = emptyList<EEditionMenu>()
override fun getItemCount(): Int = menuList.size
override fun createFragment(position: Int): Fragment {
val menu = menuList[position]
return EEditionListingFragment.newInstance(menu, date)
}
fun submitList(list: List<EEditionMenu>) {
menuList = list
notifyItemRangeChanged(0, menuList.size)
}
fun changeDate(date: String, position: Int){
this.date = date
notifyItemChanged(position)
}
}
Run Code Online (Sandbox Code Playgroud)