Recyclerview row item selection color change

后端 未结 3 1481
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-17 19:22

I am able to change the color of the text and background of imageview of the row clicked of my recyclerview in my navigation dra

3条回答
  •  -上瘾入骨i
    2021-01-17 19:49

    Simple and Best

    Inside Adapter class

    int row_index=0;
    

    inside onBindViewHOlder

    holder.titleLL.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    row_index=position;
                    notifyDataSetChanged();
                }
            });
            if (row_index==position) {
                holder.title.setTextColor(Color.RED);
            } else {
                holder.title.setTextColor(Color.BLACK);
            }
    

提交回复
热议问题