I want to stop swipe in ViewPager. But ViewPager does not have "disable swipe" API.
Creat a custom ViewPager
I creat a custom ViewPager. Custom ViewPager has a "disable swipe" API.
package jp.baroqueworksdev.myapidemo.view;
import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;
public class MyViewPager extends ViewPager {
private boolean mIsEnabledSwipe = true;
public MyViewPager(Context context) {
super(context);
}
public MyViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (!mIsEnabledSwipe) {
return false;
}
return super.onTouchEvent(event);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
if (!mIsEnabledSwipe) {
return false;
}
return super.onInterceptTouchEvent(event);
}
public void setEnabledSwipe(boolean enabled) {
mIsEnabledSwipe = enabled;
}
}