Search code examples
androidandroid-fragmentsandroid-viewpagerswipe-gesture

Disable swipe on Viewpager, allow only Swipe on pagerTitleStrip


I am facing a problem on disabling the swipe gesture on viewpager fragment. Right now, I am using custom viewpager to disable the swipe gesture.

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;
}
}

As result, this also will disable pagerTitleStrip. The reason I need to disable swipe gesture as one of my fragment contains a feature to remove item by swiping. It is possible to disable swipe only on viewpager but not on pagerTitleStrip?


Solution

  • PagerTitleStrip only shows title.
    use PagerTabStrip instead of PagerTitleStrip.