开发者

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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜