Solution 1 :
The only way to update the backing dataset currently is to call PagingSource.invalidate
to trigger another REFRESH
, which then reloads from current position via PagingSource.getRefreshKey(state)
.
e.g.,
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()
Problem :
Android Paging3 alpha03, How to remove or update item?
Help,please
Comments
Comment posted by Freshchris
Hello, please describe your problem more detailed. What exactly did you try? What is your goal? What errors did you encounter? More details help other people to understand your problem better.
Comment posted by sourcediving.com/…
check this article
Comment posted by Florian Walther
Why is this marked as duplicate with questions about Paging 2, which is a completely different library?
Comment posted by Darshana
pagingAdapter.refresh() working for me
Comment posted by mumu
Thanks, Can I specify to refresh the second page data?
Comment posted by dlam
Currently you must invalidate the entire source.
Comment posted by Florian Walther
@dlam What about using
Comment posted by dlam
@FlorianWalther Always invalidate after updates to the backing dataset. Trying to sync local state with paginated backing data is really hard to do correctly and you won’t get help on that path. For example, how will you resolve races between notifyItem and a prepend or a drop? Another hard case is restoring from cached PagingData, you will need to figure out what is presented and re-insert the correct item. SavedState is even more complicated. So I would definitely not recommend to try to be clever by using notify directly.
Comment posted by Florian Walther
@dlam Thank you for the input. If I have 500 paginated items on the list a call to