Answer the question
In order to leave comments, you need to log in
How to correctly describe the handling of keypresses in RecyclerView?
There is a RecyclerView with this template:
For it, I made this model:
class PostModel {
public String title;
public String subtitle;
public String mainText;
public int likes;
public int dislikes;
public final Random rand = new Random();
public PostModel(String newTitle, String newSubtitle, String newMainText) {
this.title = newTitle;
this.subtitle = newSubtitle;
this.mainText = newMainText;
this.likes = rand.nextInt(1000);
this.dislikes = rand.nextInt(1000);
}
}
Answer the question
In order to leave comments, you need to log in
I use the following in such cases:
Inside the onBindViewHolder, you hang an OnClickListener on the buttons. In it, from the list of elements, you select the element with the number holder.getAdapterPosition(), in it you change the value of likes / dislikes and notify that the data has changed.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question