title: How to get GestureDetector working correctly
body: <p>I have this code so far in my Activity:</p>
  
  <pre><code>private class SwipeGestureDetector extends SimpleOnGestureListener {
      // Swipe properties, you can change it to make the swipe 
      // longer or shorter and speed
      private static final int SWIPE_MIN_DISTANCE = 120;
      private static final int SWIPE_MAX_OFF_PATH = 200;
      private static final int SWIPE_THRESHOLD_VELOCITY = 200;
  
      @Override
      public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
        try {
          float diffAbs = Math.abs(e1.getY() - e2.getY());
          float diff = e1.getX() - e2.getX();
          Log.d("MainDisplayActivity", "Gesture class is running");
          if (diffAbs &gt; SWIPE_MAX_OFF_PATH)
            return false;
  
          // Left swipe
          if (diff &gt; SWIPE_MIN_DISTANCE &amp;&amp; Math.abs(velocityX) &gt; SWIPE_THRESHOLD_VELOCITY) {
             MainDisplayActivity.this.onLeftSwipe();
  
          // Right swipe
          } else if (-diff &gt; SWIPE_MIN_DISTANCE &amp;&amp; Math.abs(velocityX) &gt; SWIPE_THRESHOLD_VELOCITY) {
            MainDisplayActivity.this.onRightSwipe();
  
          }
  
        } catch (Exception e) {
          Log.e("YourActivity", "Error on gestures");
  
        }
        return false;
      }
  
    }//end of SwipeGestureDetector class
  
    //methods called by SwipeGestureDetector when the approrpiate swipes occured
    private void onLeftSwipe() {
          Toast.makeText(this, "Successfully have the swipe working for left", Toast.LENGTH_SHORT).show();
    }
  
    private void onRightSwipe() {
        Toast.makeText(this, "Successfully have the swipe working for right", Toast.LENGTH_SHORT).show();
    }
  </code></pre>
  
  <p>and I have this global: <code>private GestureDetector gestureDetector;</code></p>
  
  <p>and on <code>onCreate</code> I have this because its what I have seen people do:</p>
  
  <pre><code>gestureDetector = new GestureDetector(this, new SwipeGestureDetector());
      ((LinearLayout)findViewById(R.id.parent_main_display)).setOnTouchListener(new View.OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {
              return gestureDetector.onTouchEvent(event);
          }
      });
  </code></pre>
  
  <p>Not really sure what I am doing wrong, but nothing is happening when I swipe. Any ideas?</p>