title: How to prevent parent ViewPager from scrolling when the child ViewPager is at the last item?
body: <p>I have a nested ViewPager that works brilliantly. The only issue is, once the child ViewPager is at the last item and I scroll further, the parent ViewPager scrolls. I do not want this behaviour. </p>
  
  <p>How do I achieve this?</p>
  
  <p>Here is an example, in my <code>Activity_main.xml</code> I have the parent ViewPager, which houses three fragment pages.</p>
  
  <pre><code> &lt;android.support.v4.view.ViewPager
          android:id="@+id/viewpager"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          app:layout_behavior="@string/appbar_scrolling_view_behavior" /&gt;
  </code></pre>
  
  <p>Inside one of the fragment layouts, <code>fragment_categories.xml</code>, I have another ViewPager, which is a child to the parent viewPager in the <code>Activity_main.xml</code>,</p>
  
  <pre><code>&lt;android.support.v4.view.ViewPager
      android:id="@+id/mViewPager"
      android:layout_width="match_parent"
      android:layout_height="@dimen/offer_height"
      android:layout_marginTop="2dp"
      android:overScrollMode="never"/&gt;
  </code></pre>
  
  <p>It all works fine. But when the child viewPager reaches its last item, and I scroll more, the parent viewPager moves to the next page. I do not want this. I tried doing this by intercepting touch on the parent ViewPager before, and that didn't work. I'm guessing I'm doing it wrong? (Yes, I changed tags in the xml to <code>com.project.CustomViewPager</code> and tried this.)</p>
  
  <p><code>CustomViewPager.java</code>:</p>
  
  <pre><code>  public CustomViewPager(Context context, AttributeSet attrs) {
          super(context, attrs);
      }
  
      @Override
      protected boolean canScroll(View v, boolean checkV, int dx, int x, int y) {
          if(v != this &amp;&amp; v instanceof ViewPager) {
              return false;
          }
  
          return super.canScroll(v, checkV, dx, x, y);
      }
  </code></pre>