4
votes

I'd like to have a view pager inside my navigation drawer to switch between two lists of options when the navigation drawer is open. I'm also using the ViewPagerIndicator.

I can open the navigation drawer by swiping from the left edge of the screen towards the right and my view pager (and the indicator) shows up in the navigation drawer.

But: I can only switch between the two lists of the view pager by tapping the headline of the view pager indicator. If I try to flip between the lists displayed in the view pager by swiping the navigation drawer reacts to that touch events instead of the view pager.

How can I tell the navigation drawer to only consume swipe events if they were started OUTSIDE the navigation drawer view so that the view pager is fully functional inside the navigation drawer?

Thanks in advance!

Michael

1

1 Answers

3
votes

Catch the touch events of your ViewPager with an View.onTouchListener to disallow the parent to process the event.

viewPager.setOnTouchListener(new onTouchListener() 
{
    @Override
    public boolean onTouch(View v, MotionEvent event) 
    {
        int action = event.getAction();
        switch (action) 
        {
        case MotionEvent.ACTION_DOWN:
            // Disallow Drawer to intercept touch events.
            v.getParent().requestDisallowInterceptTouchEvent(true);
            break;

        case MotionEvent.ACTION_UP:
            // Allow Drawer to intercept touch events.
            v.getParent().requestDisallowInterceptTouchEvent(false);
            break;
        }

        // Handle viewPager touch events.
        v.onTouchEvent(event);
        return true;
    }
});