title: How to stop vertical scrolling events in ViewPager in android
body: <p>I have two views in ViewPager. I want to make it so that when vertical scrolling event occur it must reach to the view inside ViewPager so that child can take respective actions but when horizontal scrolling occurs, the viewPager must stop the event so that they can't reach to the children. I hope I a clear with my question.</p>
  
  <p>I have extended the ViewPager and override onInterceptTouchEvent method where I have to check the condition but I am not able to figure out how to do it.  I am very new to android so bear me if I am asking a naive question.</p>
  
  <p>Can someone help me to override onInterceptTouchEvent method.</p>
  
  <p>Below is my attempt:</p>
  
  <pre><code>public class CustomViewPager extends ViewPager
  {
  
      private GestureDetector mGestureDetector;
  
      public CustomViewPager(Context context, AttributeSet attrs) {
      super(context, attrs);
      mGestureDetector = new GestureDetector(context, new YScrollDetector());
      }
  
          @Override
       public boolean onInterceptTouchEvent(MotionEvent ev) {
  
      Log.e("LOG","Intercept");
      boolean ans=super.onInterceptTouchEvent(ev);
  
      if(mGestureDetector.onTouchEvent(ev))
          return false;   
      return 
     }
  
    //Now the GestureListener
  
      public class YScrollDetector extends SimpleOnGestureListener {
  
      public boolean onDown(MotionEvent e) { 
          Log.e("LOG","In down method");
           return true; 
      }
  
      @Override
      public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
          Log.e("LOG","On scroll called");
              if(Math.abs(distanceY) &gt; Math.abs(distanceX)) {
                      return true;
              }
              return false;
      }
  
  }
  </code></pre>
  
  <p>But the problem is that onScroll method is not getting any call from onInterceptTouchEvent. Can someone help me to resolve it.</p>