title: Android viewpager - detect swipe direction
body: <p>I am using a viewpager in Android und would like to control which way the user can swipe the page.</p>
  
  <p>I am using this code to detect the direction of the swipe:</p>
  
  <pre><code>// Detects the direction of swipe. Right or left. 
  // Returns true if swipe is in right direction
  public boolean detectSwipeToRight(MotionEvent event){
  
   int initialXValue = 0; // as we have to detect swipe to right
   final int SWIPE_THRESHOLD = 100; // detect swipe
   boolean result = false;
  
          try {                
              float diffX = event.getX() - initialXValue;
  
                  if (Math.abs(diffX) &gt; SWIPE_THRESHOLD ) {
                      if (diffX &gt; 0) {
  
                          // swipe from left to right detected ie.SwipeRight
                          result = false;
                      } else {
  
                          Log.e("swipeToLeft", "swipeToLeft");
                          result = true;
                      }
                  }
              } 
           catch (Exception exception) {
              exception.printStackTrace();
          }
          return result;
      }
  </code></pre>
  
  <p>This code however always returns "false". What changes must be made in the code work it to work properly?</p>