How do I change the color of the cardview after a longclick on it?

0

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>     
asked by anonymous 03.03.2015 / 15:02

1 answer

1

Have you tried this?

 <--your object-->.setOnLongClickListener(new View.OnLongClickListener() {

    //<--your object-->deve ser substituido pelo cardview em que se faz o clik.
    @Override
    public boolean onLongClick(View v) {

    //muda cor do cardview
    return true;

    }
    
04.03.2015 / 00:38