Android Paging3 alpha03,如何删除或更新项目?
请帮忙
当前更新支持数据集的唯一方法是调用
PagingSource.invalidate
来触发另一个 REFRESH
,然后通过 PagingSource.getRefreshKey(state)
从当前位置重新加载。
例如,
val backingDataSet = mutableListOf(1, 2, 3)
class MyPagingSource : PagingSource<Int, Int> {
override suspend fun load(...) = Page(
data = backingDataset,
nextKey = null,
prevKey = null,
itemsBefore = 0,
itemsAfter = 0
)
override fun getRefreshKey(state: PagingState<Int, Int>) = state.anchorPosition
}
...
var currentPagingSource: MyPagingSource? = null
val pager = Pager(...) {
MyPagingSource().also{
currentPagingSource = it
}
}
...
// To remove an item
backingDataSet.removeAt(0)
currentPagingSource.invalidate()