title: SwipeListener on ListView and ClickListener on ListView's items
body: <p>This is my <a href="https://stackoverflow.com/questions/32022717/disable-listview-items-listeners/32022964#32022964">old question</a>. However this time I have provided my code as well.</p>
  
  <p>I have a ListView with different types of rows. The row may contain text, image, video or something else. If I click on ImageView (inside the row) I will go to another activity to show the image in full screen, If I click on Video (inside the row) I will go to another activity to play he video.</p>
  
  <p>I have implemented right to left swipe listener on my ListView. If I start the ListView swipe from an empty space in ListView, the swipe works (first and second row in below image). However if I start the ListView swipe from the ListView row's item, then the swipe doesn't work (third and fourth row in below image). If I remove the click events from ImageView and Video then the swipe works even if I start the swipe from the ListView row's item i.e. in this case the swipe works on whole ListView, no matter on which row I do the swipe.</p>
  
  <p><a href="https://i.stack.imgur.com/xtgmJ.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xtgmJ.jpg" alt="enter image description here"></a></p>
  
  <p>How can I get rid on this problem? I think this can be achieved if I disable all the click events on the all the items inside ListView. How can do so? Is there any other way?</p>
  
  <p>I want both swipe on ListView and click on ListView's item.</p>
  
  <p><strong>SwipeDetector.java</strong> - For detecting swipes on the ListView</p>
  
  <pre><code>public class SwipeDetector implements View.OnTouchListener {
  
  private SwipeListener swipeListener;
  private ListView mListView;
  private int hundred;
  private boolean motionInterceptDisallowed = false;
  
  public static enum Action {
      LR, // Left to right
      RL, // Right to left
      TB, // Top to bottom
      BT, // Bottom to top
      None // Action not found
  }
  
  private static final int HORIZONTAL_MIN_DISTANCE = 30; // The minimum
  // distance for
  // horizontal swipe
  private static final int VERTICAL_MIN_DISTANCE = 80; // The minimum distance
  // for vertical
  // swipe
  private float downX, downY, upX, upY; // Coordinates
  private Action mSwipeDetected = Action.None; // Last action
  
  public SwipeDetector(Context context, ListView listView) {
      hundred = (int) context.getResources().getDimension(R.dimen.hundred);
      mListView = listView;
  }
  
  public boolean swipeDetected() {
      return mSwipeDetected != Action.None;
  }
  
  public Action getAction() {
      return mSwipeDetected;
  }
  
  /**
   * Swipe detection
   */@Override
  public boolean onTouch(View v, MotionEvent event) {
      switch (event.getAction()) {
          case MotionEvent.ACTION_DOWN:
          {
              downX = event.getX();
              downY = event.getY();
              mSwipeDetected = Action.None;
              return false; // allow other events like Click to be processed
          }
          case MotionEvent.ACTION_MOVE:
          {
              upX = event.getX();
              upY = event.getY();
  
              float deltaX = downX - upX;
              float deltaY = downY - upY;
  
              float absX = Math.abs(deltaX);
              float absY = Math.abs(deltaY);
  
              if((absX &gt;= (3 * absY)) &amp;&amp; absX &gt; HORIZONTAL_MIN_DISTANCE &amp;&amp; mListView != null &amp;&amp; !motionInterceptDisallowed) {
                  mListView.requestDisallowInterceptTouchEvent(true);
                  motionInterceptDisallowed = true;
              }
  
              if((absX &gt;= (3 * absY)) &amp;&amp; absX &lt;= hundred) {
                  if (deltaX &gt; 0) {
                      mSwipeDetected = Action.RL;
                      swipeListener.onSwipe(MotionEvent.ACTION_MOVE, Action.RL, absX);
                  }
              }
  
  
              return false;
          }
          case MotionEvent.ACTION_UP:
              swipeListener.onSwipe(MotionEvent.ACTION_UP, Action.BT, 0);
              if (mListView != null) {
                  mListView.requestDisallowInterceptTouchEvent(false);
                  motionInterceptDisallowed = false;
              }
              return false;
          case MotionEvent.ACTION_CANCEL:
              return true;
      }
      return false;
  }
  
  /**
   * Set chat send listener
   * @param listener
   */
  public void setSwipeListener(SwipeListener listener) {
      swipeListener = listener;
  }
  
  public interface SwipeListener {
      void onSwipe(int event, Action action, float x);
  }
  
  }
  </code></pre>
  
  <p>This is how I am setting SwipeDetector on my ListView</p>
  
  <pre><code>final SwipeDetector swipeDetector = new SwipeDetector(SwipeActivity.this, mListView);
      swipeDetector.setSwipeListener(mSwipeListener);
      mListView.setOnTouchListener(swipeDetector);
  </code></pre>
  
  <p>My Activity implements <code>SwipeDetector.SwipeListener</code></p>
  
  <p>Below is overridden onSwipe() method</p>
  
  <pre><code>@Override
  public void onSwipe(int event, SwipeDetector.Action action, float x) {
      switch (event) {
              case MotionEvent.ACTION_MOVE:
                  System.out.println("list move");
                  break;
              case MotionEvent.ACTION_UP:
                  System.out.println("list up");
                  break;
          }
  }
  </code></pre>
  
  <p>In my adapter I am setting onClickListener() on my TextView, ImageView and VideoView</p>
  
  <pre><code>holder.mTextView.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              System.out.println("item textview click");
          }
      });
  
  holder.mImageView.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              System.out.println("item imageview click");
          }
      });
  
  holder.mVideoView.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              System.out.println("item videoview click");
          }
      });
  </code></pre>
  
  <p>When I start the swipe from the empty area of ListView, the ListView's swipe listener captures it. However, when I start the swipe from the TextView/ImageView/VideoView then that View's onClickListener is fired instead of parent's (ListView's) onTouchListener(). </p>
  
  <p>How can I implement the same? I want that when I click on ListView's item then that item's onClick should get fired and when I swipe on the ListView's item then ListView's onSwipe should get fired.</p>