开发者

Android how to tell a finger is down

开发者 https://www.devze.com 2023-01-25 06:20 出处:网络
I understand calling onTouchEvent from views to get the location of the last touch as a motion event. How the heckcan I tell that a fingure is down on the screen and has not been lifted and when the f

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消