gesture detector problem
<p>I am trying to implement swipe in android from left to right and right to left .its not working in emulator? some times its working can anybody tell whats is problem in my code?
if anybody have working code can you give to me? </p>

<pre><code>package com.gesture;


import android.app.Activity;
import android.os.Bundle;
import android.view.GestureDetector;
 import android.app.Activity;
import android.os.Bundle;

 import android.view.GestureDetector;

 import android.view.MotionEvent;

import android.view.GestureDetector.OnGestureListener;
import android.widget.Toast;



 public class SampleGestureActivity extends Activity implements OnGestureListener  {
     public final static int SWIPE_UP    = 1; 
        public final static int SWIPE_DOWN  = 2; 
        public final static int SWIPE_LEFT  = 3; 
        public final static int SWIPE_RIGHT = 4;  
        public final static int MODE_TRANSPARENT = 0; 
        public final static int MODE_SOLID = 1; 
        public final static int MODE_DYNAMIC = 2;  
        private final static int ACTION_FAKE = -13;     
        private int swipe_Min_Distance = 100; 
        private int swipe_Max_Distance = 350; 
        private int swipe_Min_Velocity = 100;  
        private int mode = MODE_DYNAMIC; 
     private GestureDetector gestureDetector;

     @Override

     public void onCreate(Bundle savedInstanceState) {

         super.onCreate(savedInstanceState);

         setContentView(R.layout.main);

        gestureDetector = new GestureDetector(this);

     }



     @Override

     public boolean onTouchEvent(MotionEvent event) {

         return gestureDetector.onTouchEvent(event);

     }



     @Override

     public boolean onDown(MotionEvent e) {

         // Do something

         return true;

     }



     @Override
     public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
             float velocityY) {

            final float xDistance=Math.abs(e1.getX()-e2.getX());
            final float yDistance=Math.abs(e1.getY()-e2.getY());
            if(xDistance&gt;this.swipe_Max_Distance || yDistance&gt; this.swipe_Max_Distance)

                return false;
            velocityX = Math.abs(velocityX);
            velocityY = Math.abs(velocityY);
            boolean result=false;
            if(velocityX &gt; this.swipe_Min_Velocity &amp;&amp; xDistance &gt; this.swipe_Min_Distance)
            {
                if(e1.getX() &gt; e2.getX())   // right to left Move

                    Toast.makeText(SampleGestureActivity.this, "left", Toast.LENGTH_SHORT).show();

                    //this.listener.onSwipe(SWIPE_LEFT);
                else
                    Toast.makeText(SampleGestureActivity.this, "right", Toast.LENGTH_SHORT).show();

                    //this.listener.onSwipe(SWIPE_RIGHT);
                result=true;
            }
            else if(velocityY &gt; this.swipe_Min_Velocity &amp;&amp; yDistance &gt; this.swipe_Min_Distance)
            {
                if(e1.getY() &gt; e2.getY())   // bottom to top Move
                    Toast.makeText(SampleGestureActivity.this, "up", Toast.LENGTH_SHORT).show();
                else
                    Toast.makeText(SampleGestureActivity.this, "down", Toast.LENGTH_SHORT).show();
                result=true;
            }
            return result;
     }

     @Override

     public void onLongPress(MotionEvent e) { 

         // Do something

     }



     @Override

     public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,

             float distanceY) {

         // Do something

         return false;

     }



     @Override

     public void onShowPress(MotionEvent e) { 

        // Do something

     }


     @Override

     public boolean onSingleTapUp(MotionEvent e) { 

         // Do something 

         Toast t = Toast.makeText(SampleGestureActivity.this, "single", Toast.LENGTH_SHORT);
          t.show();

         return true;

     }

 }


Thanks
</code></pre>
