CarView Group select 正在 android 删除select项

CarView Group with select an deselecting items in android

Here the Branch items are aligned on a cardview within the recycleview as a button. I need to implement a click on each cardview and the color should change, but the point is that each time i click another cardView the selected cardView before should deselected. I don't even have a logic to implement this. Please help with an easy method

你可以试试这个,

public class yourRecyclerViewAdapter extends RecyclerView.Adapter<yourRecyclerViewAdapter.yourViewHolder> {

    private static int lastCheckedPos = 0;

         ... ...

    public void onBindViewHolder(ViewHolder holder, final int position) {

        if(position == lastCheckedPos) {
            holder.cardView..setCardBackgroundColor(Color.RED); //Define the re
        } else {
            holder.cardView..setCardBackgroundColor(Color.WHITE);
        }

        holder.cardView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int prevPos = lastCheckedPos;
                lastCheckedPos = position;
                notifyItemChanged(prevPos);
                notifyItemChanged(lastCheckedPos);
           }
       });
    }
       ... ... 
}

它可能会给出实现的基本逻辑