I am trying to load a recycler view that lists cards, each card has four elements. two text views(posttext, score are the id) and two buttons(minusOne and plusOne).
The code below loads the textview's content and buttons properly on all cards.
I try to implement the following behavior.
onbuttonclick of plusOne button, the score will be changed and the minusOne button is hidden.
The strange part is, the scores get updated properly on respective cards. But the hiding part appears to happen in multiple cards when the action is performed on one card.(every n+5th card). How do I fix this? Where am I going wrong? Thank you.
P.S : Suggest title edit
@Override
public void onBindViewHolder(
final MyViewHolder viewHolder, final int position) {
ParseObject model = items.get(position);
viewHolder.posttext.setText(model.getString("postText"));
viewHolder.score.setText(Integer.toString(model.getInt("score")));
viewHolder.plusOne.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ParseObject model = items.get(position);
final int score = model.getInt("score");
model.increment("score", 1);
model.saveInBackground(new SaveCallback() {
@Override
public void done(ParseException e) {
if(e==null)
{
viewHolder.score.setText(Integer.toString(score+1));
viewHolder.minusOne.setVisibility(View.GONE);
}
else{
e.printStackTrace();
}
}
});
}
});