title: RecycleView CardView long press and delete
body: <p>In my application, I have a recycleView which has many cardView controls. I want to allow the user to select the cardView controls on long press. In this operation, the user can do a long press operation on cardViews and select multiple cardViews. When the user selects a cardView using long press operation the FloatingAction button should change to delete and should allow the user to delete the selected elements from collection.
  How can I perform this operation? Below is the code which I am using.</p>
  
  <pre><code>&lt;android.support.v7.widget.CardView
      xmlns:card_view="http://schemas.android.com/apk/res-auto"
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/card_view"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      card_view:cardUseCompatPadding="true"
      card_view:cardCornerRadius="8dp"
      android:layout_marginBottom="16dp"&gt;
  
      &lt;LinearLayout android:orientation="vertical"
          android:id="@+id/display_card_view_linearLayout"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"&gt;
  
          &lt;TextView
              android:id="@+id/display_name"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:textSize="13sp"
              android:text="@string/app_name"
              android:textColor="#ffffff"
              android:paddingBottom="8dp"
              android:paddingTop="8dp"
              android:gravity="center_horizontal"
              android:layout_alignParentBottom="true"
              android:background="#1976D2"/&gt;
          &lt;ImageView
              android:id="@+id/display_image"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:contentDescription="@string/action_settings"
              android:scaleType="fitCenter" /&gt;
          &lt;TextView
              android:id="@+id/display_information"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:textSize="13sp"
              android:text="@string/app_name"
              android:textColor="#ffffff"
              android:layout_below="@+id/display_image"
              android:paddingBottom="8dp"
              android:paddingTop="8dp"
              android:gravity="center_horizontal"
              android:layout_alignParentBottom="true"
              android:background="#1976D2"/&gt;
  
  
  
      &lt;/LinearLayout&gt;
  
  &lt;/android.support.v7.widget.CardView&gt;
  </code></pre>
  
  <p>Below is adapter and holder class:</p>
  
  <pre><code>import android.content.Context;
  import android.content.Intent;
  import android.support.v7.widget.RecyclerView;
  import android.support.v7.app.AppCompatActivity;
  import android.view.View;
  import android.widget.ImageView;
  import android.widget.TextView;
  import android.widget.Toast;
  
  public class DisplayItemViewHolders extends RecyclerView.ViewHolder implements View.OnClickListener {
  
      public TextView name;
      public TextView detailedInformation;
      public ImageView image;
  
      //private final Context context;
  
      public DisplayItemViewHolders(View itemView) {
          super(itemView);
          itemView.setOnClickListener(this);
  
          //context = itemView.getActivity();
  
          name = (TextView) itemView.findViewById(R.id.display_name);
          image = (ImageView) itemView.findViewById(R.id.display_image);
      }
  
      @Override
      public void onClick(View view) {
  
      }
  }
  
  
  public class DisplayItemRecyclerViewAdapter extends RecyclerView.Adapter&lt;DisplayItemViewHolders&gt; {
  
      private List&lt;DisplayItemInformation&gt; itemList;
      private Context context;
  
      public DisplayItemRecyclerViewAdapter(Context context, List&lt;DisplayItemInformation&gt; itemList) {
          this.itemList = itemList;
          this.context = context;
      }
  
      @Override
      public DisplayItemViewHolders onCreateViewHolder(ViewGroup parent, int viewType) {
  
          View layoutView = LayoutInflater.from(parent.getContext()).inflate(R.layout.display_card, parent, false);
          layoutView.setLayoutParams(new RecyclerView.LayoutParams(RecyclerView.LayoutParams.MATCH_PARENT, RecyclerView.LayoutParams.WRAP_CONTENT));
          DisplayItemViewHolders rcv = new DisplayItemViewHolders(layoutView);
          return rcv;
      }
  
      @Override
      public void onBindViewHolder(DisplayItemViewHolders holder, int position) {
          holder.name.setText(itemList.get(position).getName());
          holder.image.setImageResource(itemList.get(position).getPhoto());
      }
  
      @Override
      public int getItemCount() {
          return this.itemList.size();
      }
  }
  </code></pre>