I have a ViewPager
with 3 Fragments
contained in it. One of the Fragments
contains another ViewPager
. which makes it a cascaded ViewPager
inside a ViewPager
.
I need to prevent the inner ViewPager
from swiping/paging while allow it to pass the scroll gestures to the contained RecyclerView
.
Yes I'm well aware that a ViewPager
inside a ViewPager
is not a great idea, yet in this case the view pager should no swipe but pass the gestures down to the child views. So there should not be a problem of two swipe mechanism in the same directions.
I tried to use the following NonSwipeableViewPager
code for the inner view pager:
public class NonSwipeableViewPager extends ViewPager {
public NonSwipeableViewPager(Context context) {
super(context);
}
public NonSwipeableViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
// Never allow swiping to switch between pages
return false;
}
@Override
public boolean onTouchEvent(MotionEvent event) {
// Never allow swiping to switch between pages
return false;
}
}
And this indeed stops the ViewPager
from paging/swiping but also prevents it from passing the touch events down to the RecyclerView
.
How can I change this ViewPager
to consume the swiping/paging gesture yet pass the scrolling gesture to the RecyclerView
?