Android的ACTION_DOWN事件自动执行几秒钟后ACTION_UP事件 [英] Android ACTION_DOWN event automatically executes ACTION_UP event after few seconds

查看:747
本文介绍了Android的ACTION_DOWN事件自动执行几秒钟后ACTION_UP事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了哪些用户有触摸图像近约10秒的应用程序。
所以,我已经注册ACTION_DOWN事件。但是,此事件在几秒后自动执行ACTION_UP事件,即使用户不拿手指。是否有此问题的任何解决方法吗?
任何帮助将大大AP preciated。

I have created an application in which user have to touch an image for near about 10 sec. So I have registered ACTION_DOWN event. But this event automatically executes ACTION_UP event after few seconds even if user does not take the finger up. Is there any workaround for this problem? Any help will be greatly appreciated.

推荐答案

我是一个Java / Android的小白但这里有一个code,对我的作品:

I'm a java/android noob but here's a code that works for me:

class HelloOnTouchListener implements OnTouchListener {
    public boolean onTouch(View v, MotionEvent e) {
        handleTouchEvent(e);
        return true;
    }
}

public void handleTouchEvent(MotionEvent e) {
    int eAct = e.getAction(); 
    if (eAct == 0) Log.d("touch", "press");
    else if (eAct == 1) Log.d("touch", "release");
}

和这里的code,它不(UP火灾两次,DOWN后第一个路口右转,然后当你真正释放​​):

And here's a code that doesn't (UP fires twice, first right after DOWN and then when you actually release):

public void handleTouchEvent(MotionEvent e) {
    int eAct = e.getAction();
    switch (eAct) {
        case MotionEvent.ACTION_DOWN: Log.d("touch", "press");
        case MotionEvent.ACTION_UP: Log.d("touch", "release");
    }
}

这篇关于Android的ACTION_DOWN事件自动执行几秒钟后ACTION_UP事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆