This repository was archived by the owner on Jan 10, 2025. It is now read-only.
This repository was archived by the owner on Jan 10, 2025. It is now read-only.
How to delete/remove PagedListAdapter item #281
Closed
Description
Currently I am using Android Architecture Components for App development everything is working along with paging library Now I want to remove recyclerview Item using PagedListAdapter to populate this we required to add a data source and from data source list is updating using LiveData no I want to remove a item from list notifyItemRemoved() is working from PagedList I am getting this exception:
java.lang.UnsupportedOperationException
java.util.AbstractList.remove(AbstractList.java:638)
Activity
sopherwang commentedon Jan 15, 2018
I had same issue.
faris-jameel commentedon Jan 15, 2018
@JiajunWong did you find any solution?
tuinui commentedon Feb 6, 2018
i got this problem to when i try to Collections.sort
guness commentedon Feb 19, 2018
I have created some custom adapter to handle this case(only a part of it actually). Luckily I was supposed to add on top of current list, so following solution only supports adding to top. However you can try to customize it.
https://gist.github.com/guness/df12d8cc4f595af1395f4a1f5bca5f00
In addition, I think some kind of merging support for the data sources would be a nice to have feature for pagination library.
jakekim0 commentedon May 18, 2018
i had same issue
shashankkapsime commentedon Jun 19, 2018
@yigit Can anyone answer this issue please.
Tenkei commentedon Jun 24, 2018
Already had this discussion here:
TL;DR: To update a pagedList you have to create a new list, this is how room update data and you have to do the same if you want to update your list.
CarGuo commentedon Jun 28, 2018
I try this after delete local data
adam-hurwitz commentedon Sep 1, 2018
After re-reading the documentation under Consider How Content Updates Work it appears the only way to have realtime updates is via implementing Room with the PagedList: If you're loading data directly from a Room database updates get pushed to your app's UI automatically.
I'm planning to connect my Firestore queries to Room in order to be able to remove items from my PagedList without having to invalidate the DataSource and reload the entire RecyclerView.
abhinav272 commentedon Sep 15, 2018
@AdamSHurwitz
If you connect your server data with
Room
to createPagedList
from it, even then when you delete an item from your local DB yourDataSource
will be invalidated automatically and you will get another version ofPagedList
from Room in your onChanged()Am I right?
adam-hurwitz commentedon Sep 15, 2018
@abhinav272 This is not the case. When an individual item in Room is added or modified the PagedList updates the corresponding entry rather than refreshing all of the data in the component. Therefore I'm able to update Room with Firestore data when it changes and allow Room + PagedList to handle the updates on individual cells. As long as Room is updated of the change the PagedList will animate and update/add/remove the item modified.
Conversely, if Firestore data was connected directly to the PagedList the entire data set would need to be invalidated / refreshed since the PagedList cannot automatically recognize individual changes from Firestore.
abhinav272 commentedon Sep 15, 2018
@AdamSHurwitz
Do you get a callback in onChanged() when you update the data in Room??
If so, that means Room has invalidated the DataSource and has provided new one with PagedList containing new data.
When I create a DataSource which is fetching data from either Room or Network, it gives me a callback in onChanged() only once when the PagedList gets created (upon creation of DataSource) and when the pages are loaded it automatically gets displayed on UI..
Make sense?
adam-hurwitz commentedon Sep 20, 2018
@abhinav272 - May you specify which onChangedd() method you are referring to?
I don't make Room updates directly. I update Firestore's database. With Firestore when a piece of information changes the Firestore listener will send an update. I listen for that update and inform Room of the change using a LiveData object. This makes it easy to keep both my backend Firestore and front-end Room data synced with minimal work.
Dilip23 commentedon Oct 2, 2018
@abhinav272
I had the same kind of issue!!!
I am building an app that receives data from network API which gets chached in Room DB. Now if i have to delete an item ,I send a request to delete an item in Remote DB(Network) and if the response is 204 , I delete an item in the Room , So then the Room DB creates a new PagedList and notifies the UI.... Right??
Or else Do we have to implement in any other way???
abhinav272 commentedon Oct 3, 2018
@Dilip23 yeah, this looks fine.
34 remaining items