Code example for ViewPager

Methods: setOnPageChangeListener

0
 
    private float mLastX;
    private boolean mLocked;
 
    public LockableViewPager(Context context) {
        super(context);
        super.setOnPageChangeListener(null); 
    } 
 
    public LockableViewPager(Context context, AttributeSet attrs) {
        super(context, attrs);
        super.setOnPageChangeListener(null); 
    } 
 
    @Override 
    public boolean onTouchEvent(MotionEvent ev) {
        if (mLock != LOCK_NONE && ev.getAction() == MotionEvent.ACTION_MOVE) {
            if (mLastX < ev.getX() && (mLock == LOCK_BOTH || mLock == LOCK_BACKWARD)) {
                mLocked = true;
            } else if (mLastX > ev.getX() && (mLock == LOCK_BOTH || mLock == LOCK_FORWARD)) {
                mLocked = true;