how to update a specific item (cardview) in recyclerview OnActivityResult

荒凉一梦 提交于 2020-01-24 19:40:25

问题


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

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

how to update just this Item ?

sorry for bad English!


回答1:


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

After that call notifyItemChanged(int) to update that specific CardView of RecyclerView

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

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.



来源:https://stackoverflow.com/questions/40503158/how-to-update-a-specific-item-cardview-in-recyclerview-onactivityresult

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!