title: How to set OnTouchListener for the entire screen?
body: <p>Please have a look at the following code. I am only posting the important sections of the code.</p>
  
  <p><strong>activity_game.xml</strong></p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:id="@+id/fullView"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:paddingBottom="@dimen/activity_vertical_margin"
      android:paddingLeft="@dimen/activity_horizontal_margin"
      android:paddingRight="@dimen/activity_horizontal_margin"
      android:paddingTop="@dimen/activity_vertical_margin"
      tools:context=".Game" &gt;
  
      &lt;TextView
          android:id="@+id/numberOfQuestionsLeft"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentLeft="true"
          android:layout_alignParentTop="true"
          android:layout_marginLeft="20dp"
          android:text="TextView" /&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p><strong>Game.java</strong></p>
  
  <pre><code>public class Game extends Activity {
  
  
  
      private View fullView;
  
  @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_game);
  
          fullView = (View)findViewById(R.id.fullView);
          fullView.setOnTouchListener(imageViewSwiped);
  
  
  
      }
  
  
   OnTouchListener imageViewSwiped = new OnSwipeTouchListener()
      {
           public boolean onSwipeRight() 
           {
              //code removed
           }
  
            public boolean onSwipeLeft() 
            {
               //code removed
                  return true;
            }
  
            public boolean onSwipeBottom()
            {
                //code removed
                return true;
            }
  
  
      };
  }
  </code></pre>
  
  <p><strong>OnSwipTouchListener.java</strong></p>
  
  <p>Note - I do not own this class of the code. It is written by another SO member.</p>
  
  <pre><code>  package game.Game;
      import android.view.GestureDetector;
      import android.view.GestureDetector.SimpleOnGestureListener;
      import android.view.MotionEvent;
      import android.view.View;
      import android.view.View.OnTouchListener;
  
      public class OnSwipeTouchListener implements OnTouchListener {
  
          private final GestureDetector gestureDetector = new GestureDetector(new GestureListener());
  
          public boolean onTouch(final View v, final MotionEvent event) {
              return gestureDetector.onTouchEvent(event);
          }
  
          private final class GestureListener extends SimpleOnGestureListener {
  
              private static final int SWIPE_THRESHOLD = 100;
              private static final int SWIPE_VELOCITY_THRESHOLD = 100;
  
              @Override
              public boolean onDown(MotionEvent e) {
                  return super.onDown(e);
              }
  
              @Override
              public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
                  boolean result = false;
                  try {
                      float diffY = e2.getY() - e1.getY();
                      float diffX = e2.getX() - e1.getX();
                      if (Math.abs(diffX) &gt; Math.abs(diffY)) {
                          if (Math.abs(diffX) &gt; SWIPE_THRESHOLD &amp;&amp; Math.abs(velocityX) &gt; SWIPE_VELOCITY_THRESHOLD) {
                              if (diffX &gt; 0) {
                                  result = onSwipeRight();
                              } else {
                                  result = onSwipeLeft();
                              }
                          }
                      } else {
                          if (Math.abs(diffY) &gt; SWIPE_THRESHOLD &amp;&amp; Math.abs(velocityY) &gt; SWIPE_VELOCITY_THRESHOLD) {
                              if (diffY &gt; 0) {
                                  result = onSwipeBottom();
                              } else {
                                  result = onSwipeTop();
                              }
                          }
                      }
                  } catch (Exception exception) {
                      exception.printStackTrace();
                  }
                  return result;
              }
          }
  
          public boolean onSwipeRight() {
              return false;
          }
  
          public boolean onSwipeLeft() {
              return false;
          }
  
          public boolean onSwipeTop() {
              return false;
          }
  
          public boolean onSwipeBottom() {
              return false;
          }
      }
  </code></pre>
  
  <p>Now, I am trying to make the make the WHOLE ACTIVITY touched enabled. Please view <code>Game.java</code> to see how I did it. But the problem is, it is not reacting to any kind of touch event! There is nothing wrong with the code <code>OnSwipTouchListener.java</code> because I have used the touch events of this by setting the listener to an <code>image view</code>.</p>
  
  <p>There must be a problem where I am trying to make the whole activity touch enabled. By saying "Whole Activity Touch Enabled" what I mean is, I need to swipe across the whole screen instead of adding the listener to an <code>imageview</code>.</p>
  
  <p>What have I done wrong here?</p>