简体   繁体   中英

Android how to tell a finger is down

I understand calling onTouchEvent from views to get the location of the last touch as a motion event. How the heck can I tell that a fingure is down on the screen and has not been lifted and when the finger is lifted?
For instance there is onKeyDown and onKeyUp for use when you are dealing with keyboard input.
So how can I find out when on fingureUp happens?

public boolean onTouch(View v, MotionEvent event) {
    switch (event.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
    case MotionEvent.ACTION_POINTER_DOWN:
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_POINTER_UP:
    case MotionEvent.ACTION_MOVE:
        // Etc...
    }
}

Then just fill in the cases with what you want to happen on these events.

onTouchListener got a parameter which is typed MotionEvent . Where you can getAction() to know if it is UP or DOWN or else.

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