HowdoImakeithappen?
Iwouldliketoaftera%w/w%w/w%w/witscolorchangedindicatingwhichone(s)Iselected!
publicstaticclassViewHolderextendsRecyclerView.ViewHolderimplementsView.OnClickListener,View.OnLongClickListener{ViewselectedOverlay;/*...*/}publicViewHolder(ViewitemView){selectedOverlay=itemView.findViewById(R.id.selected_overlay);}@OverridepublicvoidonBindViewHolder(ViewHolderholder,intposition){finalItemitem=items.get(position);//Highlighttheitemifit'sselectedholder.selectedOverlay.setVisibility(isSelected(position)?View.VISIBLE:View.INVISIBLE);}
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:foreground="?android:attr/selectableItemBackground"
app:cardUseCompatPadding="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="8dp" >
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
style="@style/Base.TextAppearance.AppCompat.Headline" />
<TextView
android:id="@+id/subtitle"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
style="@style/Base.TextAppearance.AppCompat.Subhead" />
</LinearLayout>
<View
android:id="@+id/selected_overlay"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/dim_foreground_disabled_material_dark"
android:visibility="invisible" />
</android.support.v7.widget.CardView>