santiihoyos
santiihoyos

Reputation: 53

How remove/add items from RecyclerView that uses Paging(androidx) library?

The problem comes when recycler uses Androidx paging library.

I have implemented drag and swipe to remove, but when user removes some item from list and next User scrolls down and next scroll up deleted items appear again.

How could I remove item from items source? is it possible? Do I need always call to backend -> remove -> update list?

I have created a wrapper object to manage deleted items, so when user removes any item I mark into the wrapper object deleted=true so when bind function is called I set visibility=GONE if this flag is true an vice-verse.

Upvotes: 2

Views: 1147

Answers (1)

dlam
dlam

Reputation: 3895

The only way to remove items in Paging at the moment is to go through an invalidate loop where you essentially ask Paging to reload from last scroll position.

If you are loading directly from network you might be interested in doing this in a layered way with a local cache in DB to make this less expensive via the RemoteMediator API.

For self-updating pages, there is an open bug you may follow for that feature request here: https://issuetracker.google.com/issues/160232968

Upvotes: 2

Related Questions