问题
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