问题
I am passing pagedlist values to adapter using submit list. when i update a single item consider i am clicking a like button of a feed in a recyclerview. how to update the single item.
i am following this example for paging implementation
https://github.com/saquib3705/PagingLibrarySampleApp
which just loads data and update the recyclerview. I would like to add like button for the items and update the list when user liked how to achieve it. Also look at this which is what i m exactly looking for Update list items in PagingLibrary w/o using Room (Network only)
回答1:
Assuming my guess is correct:
- Your view model has
LiveData<PagedList<Article>>
getter - You have
PagedListAdapter
implementation and set data into it viasubmitList
- You share your view model between list and list item (which is natural)
Then by adding this into your adapter constructor (naturally Article is just sample class representing some entity, you will have your own) :
super(new DiffUtil.ItemCallback<Article>() {
@Override
public boolean areItemsTheSame(@NonNull Article article1, @NonNull Article article2) {
return article1.getId().equals(article2.getId());
}
@Override
public boolean areContentsTheSame(@NonNull Article article1, @NonNull Article article2) {
return article1.equals(article2);
}
});
...you have your question solved automatically.
来源:https://stackoverflow.com/questions/55059100/updating-a-single-item-in-a-recylerview-i-am-using-paging-library-and-would-lik