简体   繁体   English

检测何时触摸停止

[英]Detect when touches stop

I am making a game in which if the user lifts up their finger, they will lose, but I don't know how to check that. 我正在做一个游戏,如果用户举起手指,他们会迷失方向,但是我不知道如何检查。 If touches are stopped, I want boolean start to be set to false. 如果触摸停止,我希望boolean start设置为false。 Any help would be greatly appretiated. 任何帮助将不胜感激。

you can use OnTouchListener. 您可以使用OnTouchListener。 you just modify below code as per your requirement 您只需根据需要修改以下代码

btn.setOnTouchListener(new OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {
                // TODO Auto-generated method stub
                  int eventaction = event.getAction();

                    switch (eventaction) {
                        case MotionEvent.ACTION_DOWN: 
                            Toast.makeText(MainActivity.this,
                                    "The button has been pressed " ,
                                    Toast.LENGTH_SHORT).show();       // finger touches the button
                            break;

                                case MotionEvent.ACTION_UP:   
                            Toast.makeText(MainActivity.this,
                                    "The button has been release",
                                    Toast.LENGTH_SHORT).show();
   // finger leaves the button
                            break;
                    }

                return false;
            }
        });

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM