更新recylerview中的单个项目.我正在使用分页库,并且想更新单个项目/行 [英] Updating a single item in a recylerview. I am using paging library and would like to update a single item/row
问题描述
我正在使用提交列表将pagedlist值传递给适配器.当我更新单个项目时,请考虑在recyclerview中单击供稿的赞"按钮.如何更新单个项目.
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
仅加载数据并更新recyclerview.我想为项目添加喜欢"按钮,并在用户喜欢如何实现时更新列表. 也看看这个,这正是我真正在寻找的东西 不使用Room(网络)更新PagingLibrary中的列表项(网络仅限
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)
推荐答案
假设我的猜测是正确的:
Assuming my guess is correct:
- 您的视图模型具有
LiveData<PagedList<Article>>
getter - 您具有
PagedListAdapter
实现,并通过submitList
将数据设置到其中
- 您在列表和列表项之间共享视图模型(自然)
- 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)
然后将其添加到您的适配器构造函数中(自然,Article只是表示某些实体的示例类,您将拥有自己的实体):
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.
这篇关于更新recylerview中的单个项目.我正在使用分页库,并且想更新单个项目/行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!