简体   繁体   English

触摸屏时如何保留onTouchEvent?

[英]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: 当我不移动手指就触摸屏幕时,Logcat的结果是:

touching the screen: YES
touching the screen: NO

I don't want show the second log until I release myfinger from the screen. 在从屏幕上释放myfinger之前,我不希望显示第二个日志。

What I'm doing wrong? 我做错了什么?

Thanks. 谢谢。

You need a break; 你需要break; in your first (and second) case. 在您的第一个(和第二个)案例中。 I've been stung by that, too. 我也为此感到ung恼。 :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 OnTouchEvent在触摸屏幕时会做出多种反应 - OnTouchEvent reacts multiple while touching the screen 为什么在不触摸屏幕的情况下触发了我的onTouchEvent? - Why is my onTouchEvent being triggered without touching the screen? Android 中触摸显示器和调用 onTouchEvent 之间的延迟有多大和一致性? - How big and consistent is the delay between touching the display and the call to onTouchEvent in Android? Android-触摸屏幕时执行某些操作 - Android - Do something while touching the screen 如果在触摸屏幕时打进电话会崩溃 - Crash if phone call comes in while touching screen 触摸屏幕时无法使用电容式按钮 - Cant use capacitive buttons while touching the screen OnTouchEvent:我想在用另一个手指在屏幕上移动时识别触摸 - OnTouchEvent: I want to recognize touches while moving with an another finger on the screen Android:当另一个手指已经触摸屏幕时,是否可以处理点击? - Android: Is it possible to handle a click while another finger is already touching the screen? 触摸屏幕即可移动矩形 - Move rectangle by touching the screen 如何在Android touchlistener中同时检测到触摸屏幕上的次要手指? - how to detect the secondary finger on touching the screen not at same time in android touchlistener?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM