title: Android: How to Stop Calling View.OnTouchListener ACTION_MOVE
body: <p>I have a simple slide action for <code>LinearLayout View</code> using <code>TouchListener</code>.</p>
  
  <p>The problem is <code>MotionEvent.ACTION_MOVE</code> keeps being called when I touch and move.</p>
  
  <p>How can I stop <code>MotionEvent.ACTION_MOVE</code>from being called?</p>
  
  <p><code>v.setOnTouchListener(null)</code> is not good: returns false and is not working.</p>
  
  <p>I want <code>MotionEvent.ACTION_MOVE</code> to be called just one time.</p>
  
  <pre><code>    private View.OnTouchListener touchEvent = new View.OnTouchListener() {
          private float tempX;
          private final float BASE_VALUE = 100;
          private final boolean LEFT = false;
          private final boolean RIGHT = true;
  
          @Override
          public boolean onTouch(View v, MotionEvent event) {
              // TODO Auto-generated method stub
  
              if(event.getAction() == MotionEvent.ACTION_DOWN){
                  tempX = event.getX();
              }
  
              if(event.getAction() == MotionEvent.ACTION_MOVE){
                  if(event.getX() &lt; (tempX + BASE_VALUE)){
                      changeView(LEFT);
                  }else if(event.getX() &gt; (tempX + BASE_VALUE)){
                      changeView(RIGHT);
                  }
              }
  </code></pre>
  
  <p>It is not working perfectly.</p>
  
  <p>But this implementation is not bad (this code is my idea).</p>
  
  <p>The code:</p>
  
  <pre><code>private View.OnTouchListener touchEvent = new View.OnTouchListener() {
      private VelocityTracker mVelocityTracker;
      private float tempX;
      private final int MIN_DISTANCE = 120;
      private final int THRESHOLD_VELOCITY = 200; 
      private final boolean LEFT = false;
      private final boolean RIGHT = true;
      private MotionEvent cancelEvent = MotionEvent.obtain(100, 100, MotionEvent.ACTION_CANCEL, 0, 0, 0);
      @Override
      public boolean onTouch(View v, MotionEvent event) {
          // TODO Auto-generated method stub
          if(event.getAction() == MotionEvent.ACTION_DOWN){
              Log.d(TAG, "Down");
              mVelocityTracker = VelocityTracker.obtain();
              mVelocityTracker.addMovement(event);
              tempX = event.getX();
          }
          if(event.getAction() == MotionEvent.ACTION_MOVE){
              mVelocityTracker.addMovement(event);
              mVelocityTracker.computeCurrentVelocity(100);
              float velocityX = mVelocityTracker.getXVelocity();
              if(tempX - event.getX() &gt; MIN_DISTANCE 
                     &amp;&amp; Math.abs(velocityX) &gt; THRESHOLD_VELOCITY){
                     Log.d(TAG, "LEFT");
                     changeView(LEFT);
              }else if(event.getX() - tempX &gt; MIN_DISTANCE 
                     &amp;&amp; Math.abs(velocityX) &gt; THRESHOLD_VELOCITY){
                     Log.d(TAG, "RIGHT");
                     changeView(RIGHT);
              }
              v.dispatchTouchEvent(cancelEvent);
          }
  </code></pre>