Disable just tapping on ViewPager

236 views Asked by At

I have a ViewPager which scrolls through emails, it requests an email when the user stops scrolling for a brief amount of time, with a scheduler.

During this pause I don't want any of the placeholder buttons that are on the page being loaded from being clicked. During this paging event, therefore I would like to allow swiping, since the user can keep swiping to a different email but disable tapping on sender / receiver or interactive elements within the email which are still placeholder and will lead nowhere.

I have tried to do something like this so far on the view pager:

// Set a simple gesture to handle our click request, allowing everything else
final GestureDetector.SimpleOnGestureListener dsl_simpleDetector = new GestureDetector.SimpleOnGestureListener() {
    public boolean onSingleTapUp (MotionEvent motionEvent) {
        // Don't want to do anything with this if timer is running
        final ExchangeEmailActivity ds_act = (ExchangeEmailActivity) getActivity();
        if (ds_act.dsc_timer != null) { // We're waiting for the page to load still
            return false; // Handle it by doing nothing
        } else {
            return true; // Let it be handled as necessary
        }
    }
};

// The listener will call the simple gesture above to handle it
vp_pager.setOnTouchListener(new View.OnTouchListener() {
    @Override
    public boolean onTouch(View view, MotionEvent motionEvent) {
        return (dsl_simpleDetector.onSingleTapUp(motionEvent));
    }
});
1

There are 1 answers

3
IIIIIIIIIIIIIIIIIIIIII On

if you don't want your users to click a button -> disable the button. It is bad design to "hack" the touch listener to just prevent a user from clicking buttons.