title: Android list view Right / Left swipes like call logs
body: <p>I have an Android application in which there is List View Like this one </p>
  
  <p><img src="https://i.stack.imgur.com/vjkBK.jpg" alt="enter image description here"></p>
  
  <p>Now I want to perform two different activities on right/Left swipe of the List Items in the same way How native call log works </p>
  
  <p>Right Swipe of list </p>
  
  <p><img src="https://i.stack.imgur.com/DTTGa.jpg" alt="enter image description here"> </p>
  
  <p>I want this type of swipes. Can anyone know how to make it happen. Basically I wan to implement <code>SimpleOnGestureListener</code>.</p>
  
  <p>I have read a post answered by <strong>sir gav</strong> <a href="https://stackoverflow.com/questions/937313/android-basic-gesture-detection">Fling gesture detection on grid layout</a> and after that I am successful in implementing left swipe and right swipe detection but the only thing I am not getting on which List Item the swipe has occurred.</p>
  
  <p><strong>Update</strong> 24 May 2013</p>
  
  <p>Now I am able to detect swipe action using this code -- </p>
  
  <p><strong>SwipeDetector.java</strong></p>
  
  <pre><code>/**
   * Class swipe detection to View
   */
  public class SwipeDetector implements View.OnTouchListener {
  
      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 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;
  
                  // horizontal swipe detection
                  if (Math.abs(deltaX) &gt; HORIZONTAL_MIN_DISTANCE) {
                      // left or right
                      if (deltaX &lt; 0) {
  
                          mSwipeDetected = Action.LR;
                          return true;
                      }
                      if (deltaX &gt; 0) {
  
                          mSwipeDetected = Action.RL;
                          return true;
                      }
                  } else
  
                  // vertical swipe detection
                  if (Math.abs(deltaY) &gt; VERTICAL_MIN_DISTANCE) {
                      // top or down
                      if (deltaY &lt; 0) {
  
                          mSwipeDetected = Action.TB;
                          return false;
                      }
                      if (deltaY &gt; 0) {
  
                          mSwipeDetected = Action.BT;
                          return false;
                      }
                  }
                  return true;
              }
          }
          return false;
      }
  
  }
  </code></pre>
  
  <p>Now use it with your ListView in this fashion</p>
  
  <pre><code>    // Set the touch listener
      final SwipeDetector swipeDetector = new SwipeDetector();
      lv.setOnTouchListener(swipeDetector);
  </code></pre>
  
  <p>In your <code>setOnItemClickListener</code> you can detect the swipe events like these</p>
  
  <pre><code>lv.setOnItemClickListener(new OnItemClickListener() {
  
  
      @Override
      public void onItemClick(AdapterView &lt;? &gt; parent, View view,
          int position, long id) {
  
          if (swipeDetector.swipeDetected()) {
              if (swipeDetector.getAction() == SwipeDetector.Action.LR) {
  
                  Toast.makeText(getApplicationContext(),
                      "Left to right", Toast.LENGTH_SHORT).show();
  
              }
              if (swipeDetector.getAction() == SwipeDetector.Action.RL) {
  
                  Toast.makeText(getApplicationContext(),
                      "Right to left", Toast.LENGTH_SHORT).show();
  
              }
          }
      }
  });
  </code></pre>
  
  <p>But still I am not able to animate the swipe like these:</p>
  
  <p><img src="https://i.stack.imgur.com/O44mw.png" alt="enter image description here"></p>