Android Paging3 alpha03,如何删除或更新项目?
请帮帮忙
发布于 2020-08-08 12:11:25
当前更新备份数据集的唯一方法是调用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()https://stackoverflow.com/questions/63305182
复制相似问题