FragmentStateAdapter 抛出
java.lang.IllegalStateException:违反设计假设,
当设备旋转时。我该如何解决这个问题?
private inner class PagerAdapter : FragmentStateAdapter(this) {
private val ids = LongSparseArray<Media>()
override fun getItemCount(): Int = adapter.itemCount
override fun getItemId(position: Int): Long {
return adapter.source!![position].time
}
override fun containsItem(itemId: Long): Boolean {
return ids[itemId] != null
}
}
例外
java.lang.IllegalStateException: Design assumption violated.
at androidx.viewpager2.adapter.FragmentStateAdapter.placeFragmentInViewHolder(FragmentStateAdapter.java:270)
at androidx.viewpager2.adapter.FragmentStateAdapter.onViewAttachedToWindow(FragmentStateAdapter.java:259)
at androidx.viewpager2.adapter.FragmentStateAdapter.onViewAttachedToWindow(FragmentStateAdapter.java:68)