1

I have an onClick method that sets the current CardView to a colour, but then all the previous CardViews that had theironClick method invoked also have their colour changed. What I am trying to do is to reset all the other CardViews to their original colour and set the current CardView to a different colour.

This is my code:

public ViewHolder(View view) {
    super(view);
    cardView = (CardView) view.findViewById(R.id.card_view);
    view.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            cardView.setBackgroundColor(Color.RED);
        }
    });
}

So the above method sets the background colour for that cardview which is great but I want the others to return back to their original colours. How would I go about doing that?

Thanks

1 Answers1

0

you use simple list view? if so than it is not correct behaviour. why you just do not set list.setOnItemClick where you can set new color into adapter and call onDataSetChanged?