简体   繁体   中英

How to retain onTouchEvent while touching screen?

I have the following method to handle when I touch the screen:

public boolean onTouchEvent(MotionEvent event) {

    boolean touchDown = true;
    switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
            Log.i(TAG,"touching the screen: YES");
        case MotionEvent.ACTION_UP:
            touchDown = false;
            Log.i(TAG,"touching the screen: NO");
    }
    return touchDown;

}

The result of the Logcat when I touch the screen without removing my finger is:

touching the screen: YES
touching the screen: NO

I don't want show the second log until I release myfinger from the screen.

What I'm doing wrong?

Thanks.

You need a break; in your first (and second) case. I've been stung by that, too. :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM