如何在recyclerview OnActivityResult中更新特定项目(卡片视图) [英] how to update a specific item (cardview) in recyclerview OnActivityResult

查看:232
本文介绍了如何在recyclerview OnActivityResult中更新特定项目(卡片视图)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MainActivty里面有一个片段,在这个带有CardView的文章的Fragment RecyclerView里面(在这个卡片内,我有喜欢的按钮和喜欢的计数器),当用户单击cardView时,它将打开DetailsActivity

I have a Fragment inside MainActivty, and inside this Fragment RecyclerView of Articles with cardView (inside this card i have like button and like counter) and when the user click on the cardView will open DetailsActivity that

我想在onBackPressed进行更新时仅此项取决于DetailsActivity中更改的数据(如按钮和计数器)

and I want when onBackPressed to update just this item depends on the data changed (like button and like counter) in DetailsActivity

如何仅更新此项目?

对不起,英语不好!

推荐答案

首先更新适配器特定位置项的数据.

First update the data of that specific position item of adapter.

此后调用 notifyItemChanged (int)更新RecyclerView

通知任何注册的观察员position处的项目已更改.等同于调用notifyItemChanged(position, null);

Notify any registered observers that the item at position has changed. Equivalent to calling notifyItemChanged(position, null);

这是项目更改事件,而不是结构更改事件.它指示position处的任何数据反射均已过时,应进行更新. position处的项目保留相同的身份.

This is an item change event, not a structural change event. It indicates that any reflection of the data at position is out of date and should be updated. The item at position retains the same identity.

这篇关于如何在recyclerview OnActivityResult中更新特定项目(卡片视图)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆