Search code examples
javaandroidontouchlisteneractioneventandroid-touch-event

Android: onTouchEvent breaks


i am creating an android game and have an onTouchEvent like this:

 @Override
public boolean onTouchEvent(MotionEvent event) {

    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        if (!action) {
            action = true; 
        }
    } else {
        action=false;
    }
    return true;
}

My problen is now, that action is false as soon as i swipe my finger a little bit.

thanks for helping,
Florian


Solution

  • If you want to return true even when a swipe input occurs, you could store the last action to compare if the last action was ACTION_DOWN and if the current 'event.getAction()' is also ACTION_DOWN, then you can assume that the swipe action occurs (also if the previous 'x' and 'y' positions differ to the current 'x' and 'y' positions), therefore still return true. Any other scenario, you can return false.

    You could also try looking in the android API documentation about a swipe input action/gesture.

    Hope that is helpful.