title: How to disable ViewPager from swiping in one direction
body: <p>I want to allow the user swipe in a <code>ViewPager</code> only from right to left. So once he passed a page he can't come back to it. How can this be done?</p>
  
  <p>I tried <a href="https://stackoverflow.com/questions/12224581/viewpage-stop-swiping-in-a-certain-direction"><strong>this</strong></a> solution:</p>
  
  <pre><code>public class CustomViewPager extends ViewPager {
  
  float lastX = 0;
  
  boolean lockScroll = false;
  
  public CustomViewPager(Context context, AttributeSet attrs) {
      super(context, attrs);
  }
  
  public CustomViewPager(Context context) {
      super(context);
  }
  
  @Override
  public boolean onTouchEvent(MotionEvent ev) {
  
      switch (ev.getAction()) {
      case MotionEvent.ACTION_DOWN:
          lastX = ev.getX();
          lockScroll = false;
          return super.onTouchEvent(ev);
      case MotionEvent.ACTION_MOVE:
  
          if (lastX &gt; ev.getX()) {
              lockScroll = false;
          } else {
              lockScroll = true;
          }
  
          lastX = ev.getX();
          break;
      }
  
      lastX = ev.getX();
  
      if(lockScroll) {
          return false;
      } else {
          return super.onTouchEvent(ev);
      }
  }
  }
  </code></pre>
  
  <p>But it still allows me to poorly swipe in the other direction.</p>