MotionEvents triggering no matter what in Android

95 views Asked by At

I have this code for my MotionEvents in Android:

@Override
public boolean onTouchEvent(MotionEvent event){

    int action = event.getActionMasked();

    switch (action){
        case MotionEvent.ACTION_UP:
            mGameview.moveUp(30);
            break;
        case MotionEvent.ACTION_DOWN:
            mGameview.moveDown(30);
            break;
    }

    return true;
}

However, instead of these things only triggering when I drag my finger up/down, they both happen simultaneously no matter what I do in the app, for example when I tap, drag left and right.

1

There are 1 answers

2
kenzo On

Try to get action by:

int action = event.getAction() & MotionEvent.ACTION_MASK;