Sushant
Sushant

Reputation: 1874

Viewpager inside Viewpager make parent Viewpager swipable?

Scenario:

I have a ViewPager which contains another ViewPager

Requirement

I want to disable swipe on child ViewPager, instead parent ViewPager should handle the swipe events.

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

I Used the above code to disable swipe events on child ViewPager but parent ViewPager still won't handle the swipe.

Upvotes: 0

Views: 578

Answers (1)

Chompy
Chompy

Reputation: 171

Instead of using the above code in your child ViewPager, use the following:

public class NoSwipeViewPager extends android.support.v4.view.ViewPager {

    public NoSwipeViewPager(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public boolean canScrollHorizontally(int direction) {
        return false;
    }
}

Upvotes: 1

Related Questions