title: How to add swipe functionality on Android CardView?
body: <p>I have a single CardView that contains two TextViews and two ImageViews. I want to be able to swipe left and right to "dismiss". I actually want swipe right to send an Intent but that can be done later. For now, I want to be able to dismiss the CardView by swiping left or right. I also want the animation of swiping.</p>
  
  <p>I tried using <a href="https://github.com/romannurik/Android-SwipeToDismiss/blob/master/src/com/example/android/swipedismiss/SwipeDismissTouchListener.java" rel="noreferrer"><code>romannurik's SwipeDismissTouchListener</code></a> but the CardView does not respond to swiping.</p>
  
  <p>If anyone has a better solution than <code>romannurik's</code> custom listener, please share.</p>
  
  <p><strong>Here's my CardView layout:</strong></p>
  
  <pre><code>&lt;android.support.v7.widget.CardView
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_below="@id/generate"
      map:cardCornerRadius="@dimen/_3sdp"
      map:cardElevation="@dimen/_8sdp"
      android:id="@+id/restaurantContainer"&gt;
  
      &lt;LinearLayout
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:orientation="vertical"&gt;
  
          &lt;LinearLayout
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:orientation="horizontal"&gt;
  
              &lt;LinearLayout
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:orientation="vertical"&gt;
  
                  &lt;ImageView
                      android:id="@+id/thumbnail"
                      android:layout_width="@dimen/_75sdp"
                      android:layout_height="@dimen/_75sdp"
                      android:layout_margin="@dimen/_5sdp" /&gt;
  
                  &lt;ImageView
                      android:id="@+id/rating"
                      android:layout_width="@dimen/_75sdp"
                      android:layout_height="@dimen/_15sdp"
                      android:layout_margin="@dimen/_5sdp" /&gt;
              &lt;/LinearLayout&gt;
  
              &lt;LinearLayout
                  android:layout_width="fill_parent"
                  android:layout_height="fill_parent"
                  android:orientation="vertical"&gt;
  
                  &lt;TextView
                      android:id="@+id/name"
                      android:layout_width="fill_parent"
                      android:layout_height="wrap_content"
                      android:layout_margin="@dimen/_5sdp"
                      android:gravity="top"
                      android:textAppearance="?android:attr/textAppearanceLarge" /&gt;
  
                  &lt;TextView
                      android:id="@+id/categories"
                      android:layout_width="fill_parent"
                      android:layout_height="fill_parent"
                      android:layout_margin="@dimen/_5sdp"
                      android:textAppearance="?android:attr/textAppearanceMedium" /&gt;
              &lt;/LinearLayout&gt;
  
          &lt;/LinearLayout&gt;
  
          &lt;LinearLayout
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"&gt;
  
              &lt;com.google.android.gms.maps.MapView
                  android:id="@+id/mapView"
                  android:layout_width="fill_parent"
                  android:layout_height="fill_parent"
                  map:cameraZoom="14"
                  map:liteMode="true"
                  map:mapType="normal" /&gt;
  
          &lt;/LinearLayout&gt;
  
      &lt;/LinearLayout&gt;
  
  &lt;/android.support.v7.widget.CardView&gt;
  </code></pre>
  
  <p><strong>How I setup the SwipeDismissTouchListener:</strong></p>
  
  <pre><code>RelativeLayout rootLayout;
  CardView restaurantCardView;
  
  ...
  
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  
          rootLayout = (RelativeLayout) inflater.inflate(R.layout.fragment_main, container, false);
  
          restaurantCardView = (CardView) rootLayout.findViewById(R.id.restaurantContainer);
  
          restaurantCardView.setOnTouchListener(new SwipeDismissTouchListener(restaurantCardView, null, new SwipeDismissTouchListener.DismissCallbacks() {
              @Override
              public boolean canDismiss(Object token) {
                  Log.d("Chris", "canDismiss() called with: " + "token = [" + token + "]");
                  return true;
              }
  
              @Override
              public void onDismiss(View view, Object token) {
                  Log.d("Chris", "onDismiss() called with: " + "view = [" + view + "], token = [" + token + "]");
              }
          }));
      ....
  
      return rootLayout;
  </code></pre>
  
  <p>I am able to see the log from <code>canDismiss(...)</code> but not from <code>onDismiss(...)</code>.</p>