I have a Recycler View that constains rows with an TextView and two Buttons. The buttons work as up/downvotes and can only be clicked once at a time. If one of the buttons is clicked, the other one cannot be clicked if the previous was not "unclicked". The TextView represents the score.

The problem I'm having is that the the text in the TextView is being handled correctly, increasing only when it is possible, however, the background color of the row is always wrong and does not follow the rule.
I am using SQLite as a table for checking if the post was up/downvoted and setting "null" when none of the buttons is clicked.

The following code is written in the MainActivity.java.

```
   scoreAdapter.setOnButtonDownClickListener(new ScoreAdapter.onButtonClickListener() {
        @Override
        public void onButtonClick(View parent, Button btn, int position) {
            int postId = (int) parent.getTag();
            String vote = databaseHandler.getVote(postId);
            if(vote.equals("down")){
                scoreAdapter.setScore(position,Integer.parseInt(scoreAdapter.getScore(position)) + 1);
                databaseHandler.writeVote((int) parent.getTag(),"null");
                parent.setBackgroundColor(getResources().getColor(R.color.notVoted,getApplication().getTheme()));
                scoreAdapter.notifyItemChanged(position);
            }else if(! vote.equals("up")){
                scoreAdapter.setScore(position,Integer.parseInt(scoreAdapter.getScore(position)) - 1);
                databaseHandler.writeVote((int) parent.getTag(),"down");
                parent.setBackgroundColor(getResources().getColor(R.color.downVoted,getApplication().getTheme()));
                scoreAdapter.notifyItemChanged(position);
            }
            Log.i(parent.getTag().toString(),databaseHandler.getVote((int) parent.getTag()));
        }
    });

    scoreAdapter.setOnButtonUpClickListener(new ScoreAdapter.onButtonClickListener() {
        @Override
        public void onButtonClick(View parent, Button btn, int position) {
            int postId = (int) parent.getTag();
            String vote = databaseHandler.getVote(postId);
            if(vote.equals("up")){
                scoreAdapter.setScore(position,Integer.parseInt(scoreAdapter.getScore(position)) - 1);
                databaseHandler.writeVote((int) parent.getTag(),"null");
                parent.setBackgroundColor(getResources().getColor(R.color.notVoted,getApplication().getTheme()));
                scoreAdapter.notifyItemChanged(position);
            }else if(! vote.equals("down")){
                scoreAdapter.setScore(position,Integer.parseInt(scoreAdapter.getScore(position)) + 1);
                databaseHandler.writeVote((int) parent.getTag(),"up");
                parent.setBackgroundColor(getResources().getColor(R.color.upVoted,getApplication().getTheme()));
                scoreAdapter.notifyItemChanged(position);
            }
            Log.i(parent.getTag().toString(),databaseHandler.getVote((int) parent.getTag()));
        }
    });

```

ScoreAdapter is the RecyclerView adapter. I know the interfaces used for the onClick Event should be correct because the TextView modification is correct. The following code is the code inside the ViewHolder class.

```
public interface onButtonClickListener{
    void onButtonClick(View parent, Button btn, int position);
}

public class ViewHolder extends RecyclerView.ViewHolder{
    public TextView score;
    public Button buttonUp;
    public Button buttonDown;

    public ViewHolder(View v){
        super(v);
        score = (TextView) v.findViewById(R.id.textScore);
        buttonUp = (Button) v.findViewById(R.id.btnUp);
        buttonDown = (Button) v.findViewById(R.id.btnDown);

        buttonDown.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Log.i("Down","clicked");
                if(onButtonDownClickListener != null){
                    int position = getAdapterPosition();
                    if(position != RecyclerView.NO_POSITION){
                        onButtonDownClickListener.onButtonClick(itemView, buttonDown, position);
                    }
                }
            }
        });

        buttonUp.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Log.i("Up","clicked");
                if(onButtonUpClickListener != null){
                    int position = getAdapterPosition();
                    if(position != RecyclerView.NO_POSITION){
                        onButtonUpClickListener.onButtonClick(itemView, buttonUp, position);
                    }
                }
            }
        });

```

How can I fix the background color change? Is it possible that by clicking one of the buttons, the other one also receives the click?

EDIT:

MainAcitivty.java

```
public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    final RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
    ArrayList<Score> scores = new ArrayList<>();
    scores.add(new Score(2,0));
    scores.add(new Score(0,1));
    scores.add(new Score(-1,2));
    scores.add(new Score(3,3));
    scores.add(new Score(10,4));
    scores.add(new Score(50,5));
    scores.add(new Score(62,6));
    scores.add(new Score(8,7));
    scores.add(new Score(-5,8));
    scores.add(new Score(12,10));
    scores.add(new Score(26,11));
    scores.add(new Score(32,12));
    scores.add(new Score(9,13));
    scores.add(new Score(95,14));
    final LocalDatabaseHandler databaseHandler = new LocalDatabaseHandler(this);

    final ScoreAdapter scoreAdapter = new ScoreAdapter(this,scores);
    recyclerView.setAdapter(scoreAdapter);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));

    scoreAdapter.setOnButtonDownClickListener(new ScoreAdapter.onButtonClickListener() {
        @Override
        public void onButtonClick(View parent, Button btn, int position) {
            int postId = (int) parent.getTag();
            String vote = databaseHandler.getVote(postId);
            if(vote.equals("down")){

                scoreAdapter.setScore(position,Integer.parseInt(scoreAdapter.getScore(position)) + 1);
                databaseHandler.writeVote((int) parent.getTag(),"null");
                btn.setBackgroundColor(getResources().getColor(R.color.notVoted));

            }else if(! vote.equals("up")){

                scoreAdapter.setScore(position,Integer.parseInt(scoreAdapter.getScore(position)) - 1);
                databaseHandler.writeVote((int) parent.getTag(),"down");
                btn.setBackgroundColor(getResources().getColor(R.color.downVoted));

            }
        }
    });

    scoreAdapter.setOnButtonUpClickListener(new ScoreAdapter.onButtonClickListener() {
        @Override
        public void onButtonClick(View parent, Button btn, int position) {
            int postId = (int) parent.getTag();
            String vote = databaseHandler.getVote(postId);
            if(vote.equals("up")){

                scoreAdapter.setScore(position,Integer.parseInt(scoreAdapter.getScore(position)) - 1);
                databaseHandler.writeVote((int) parent.getTag(),"null");
                btn.setBackgroundColor(getResources().getColor(R.color.notVoted));

            }else if(! vote.equals("down")){

                scoreAdapter.setScore(position,Integer.parseInt(scoreAdapter.getScore(position)) + 1);
                databaseHandler.writeVote((int) parent.getTag(),"up");
                btn.setBackgroundColor(getResources().getColor(R.color.upVoted));

            }
        }
    });

    scoreAdapter.setOnItemClickListener(new ScoreAdapter.onItemClickListener() {
        @Override
        public void onItemClick(View view, int position) {
            Toast.makeText(getApplicationContext(),Integer.toString((int) view.getTag()),Toast.LENGTH_SHORT).show();
        }
    });

    recyclerView.addItemDecoration(new DividerItemDecoration(this,DividerItemDecoration.VERTICAL));
}

```

}

ScoreAdapter.java

```
public class ScoreAdapter extends RecyclerView.Adapter<ScoreAdapter.ViewHolder> {

public interface onItemClickListener{
    void onItemClick(View view, int position);
}

public interface onButtonClickListener{
    void onButtonClick(View parent, Button btn, int position);
}

public class ViewHolder extends RecyclerView.ViewHolder{
    TextView score;
    Button buttonUp;
    Button buttonDown;
    View parent;

    public ViewHolder(View v){
        super(v);
        score = (TextView) v.findViewById(R.id.textScore);
        buttonUp = (Button) v.findViewById(R.id.btnUp);
        buttonDown = (Button) v.findViewById(R.id.btnDown);
        parent = v;

        buttonDown.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Log.i("Down","clicked");
                if(onButtonDownClickListener != null){
                    int position = getAdapterPosition();
                    if(position != RecyclerView.NO_POSITION){
                        onButtonDownClickListener.onButtonClick(parent, buttonDown, position);
                    }
                }
            }
        });

        buttonUp.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Log.i("Up","clicked");
                if(onButtonUpClickListener != null){
                    int position = getAdapterPosition();
                    if(position != RecyclerView.NO_POSITION){
                        onButtonUpClickListener.onButtonClick(parent, buttonUp, position);
                    }
                }
            }
        });

        v.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Log.i("View","clicked");
                if(onItemClickListener != null){
                    int position = getAdapterPosition();
                    if(position != RecyclerView.NO_POSITION){
                        onItemClickListener.onItemClick(parent,position);
                    }
                }
            }
        });
    }

}

private List<Score> scoreList;
private Context context;
private onItemClickListener onItemClickListener;
public onButtonClickListener onButtonUpClickListener;
public onButtonClickListener onButtonDownClickListener;

public ScoreAdapter(Context context,List<Score> scores){
    this.scoreList = scores;
    this.context = context;
}

public void setOnItemClickListener(ScoreAdapter.onItemClickListener onItemClickListener) {
    this.onItemClickListener = onItemClickListener;
}

public void setOnButtonUpClickListener(onButtonClickListener onButtonUpClickListener) {
    this.onButtonUpClickListener = onButtonUpClickListener;
}

public void setOnButtonDownClickListener(onButtonClickListener onButtonDownClickListener) {
    this.onButtonDownClickListener = onButtonDownClickListener;
}

public List<Score> getScoreList() {
    return scoreList;
}

public Context getContext() {
    return context;
}

public ScoreAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType){
    Context context = parent.getContext();
    View scoreView = LayoutInflater.from(context).inflate(R.layout.data_layout,parent,false);
    return new ScoreAdapter.ViewHolder(scoreView);
}

public void onBindViewHolder(ScoreAdapter.ViewHolder viewHolder, int position){
    Score s = scoreList.get(position);
    viewHolder.parent.setTag(s.getId());
    viewHolder.score.setText(s.getScore());
}

public int getItemCount(){
    return scoreList.size();
}

public String getScore(int position){
    return getScoreList().get(position).getScore();
}

public void setScore(int position,int score){
    getScoreList().get(position).setScore(Integer.toString(score));
    notifyItemChanged(position);
}

```

}