I have one recyclerview recyclerview row contains two textviews
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:elevation="2dp"
android:id="@+id/l1"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_marginBottom="@dimen/margin_12"
android:layout_marginLeft="@dimen/margin_22"
android:layout_marginRight="@dimen/margin_22"
android:layout_marginTop="@dimen/margin_12"
android:orientation="vertical">
<TextView
android:id="@+id/tv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="fdgdfgfdgfdg"
android:textAlignment="center"
android:textColor="@color/color"
android:textSize="@dimen/text_size_16" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal">
<TextView
android:id="@+id/tv2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="jh"
android:textColor="@color/color"
android:textSize="@dimen/text_size_9" />
</LinearLayout>
</LinearLayout>
What i want is to change the textcolor of clicked item to red. and other items to black
What i am doing in Adapter is
class MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
TextView tv_1, tv_2;
LinearLayout l1 ;
/*package */ MyViewHolder(final View itemView) {
super(itemView);
l1 = itemView.findViewById(R.id.l1) ;
tv1 = itemView.findViewById(R.id.tv1);
tv2 = itemView.findViewById(R.id.tv2);
tv1.setOnClickListener(this);
}
@Override
public void onClick(View view) {
tv1 = itemView.findViewById(R.id.tv1);
tv1.setTextColor(Color.parseColor("#d30c20"));
tv2.setTextColor(Color.parseColor("#d30c20"));
String id = tv1.getText().toString();
mItemClickListener.onItemClick(view, getAdapterPosition(), id);
}
}
this works fine but when i click other item i want to reset item color of previousy selected item to its original color.
In short i want to change the color of both selected item and unselected item every time
how to do this ???