[英]RecyclerView Update Single Item's Child
My Recyclerview
list is as in the picture.我的Recyclerview
列表如图所示。
I want to update the child (example: just the 'Like' part) of a single item in my list.我想更新列表中单个项目的子项(例如:只是“喜欢”部分)。 I did some research on the subject.我对这个主题做了一些研究。 I can update the whole item.我可以更新整个项目。 However, what I need is to update one child of the item.但是,我需要更新该项目的一个子项。 I need code snippet on this.我需要这方面的代码片段。 I'm new here, thanks in advance.我是新来的,先谢谢了。
Let's say you have a class named User and you are passing an ArrayList(that contains different User objects) to the RecyclerView Adapter.假设您有一个名为User的 class 并且您将一个 ArrayList(包含不同的 User 对象)传递给 RecyclerView 适配器。
public class User
{
....
private String name;
private int age;
//Getters, setters, etc ....
}
So for updating just the age , simply update that object present at that specific position in the list and then just refresh the RecyclerView.因此,对于仅更新年龄,只需更新列表中特定 position 中的 object,然后刷新 RecyclerView。
....
users.get(position).setAge(xyz);
userAdapter.notifyItemChanged(position);
....
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.