在Android中捕获双击

时间:2012-01-14 07:11:17

标签: java android andengine

我正在使用AndEngine捕获onSceneTouchEvent的事件。

我想做的是不允许它捕获用户双击屏幕。

无论如何都要检测双击还是禁用它们?

由于

1 个答案:

答案 0 :(得分:3)

编辑:看了一下之后,我认为这可能更适合你:

// in an onUpdate method

onUpdate(float secondsElapsed){

if(touched){
if(seconds > 2){
doSomething();
touched = false;
seconds = 0;
} else{
seconds += secondsElapsed;
}
}

}

取自:http://www.andengine.org/forums/gles1/delay-in-touchevent-t6087.html

基于上面的评论,我确信你可以使用SystemClock来解决以下问题。

您可以添加延迟,类似于此:

public boolean onTouch(View v, MotionEvent event) {
            // TODO Auto-generated method stub
            if(firstTap){
                thisTime = SystemClock.uptimeMillis();
                firstTap = false;
            }else{
                prevTime = thisTime;
                thisTime = SystemClock.uptimeMillis();

                //Check that thisTime is greater than prevTime
                //just incase system clock reset to zero
                if(thisTime > prevTime){

                    //Check if times are within our max delay
                    if((thisTime - prevTime) <= DOUBLE_CLICK_MAX_DELAY){

                        //We have detected a double tap!
                        Toast.makeText(DoubleTapActivity.this, "DOUBLE TAP DETECTED!!!", Toast.LENGTH_LONG).show();
                        //PUT YOUR LOGIC HERE!!!!

                    }else{
                        //Otherwise Reset firstTap
                        firstTap = true;
                    }
                }else{
                    firstTap = true;
                }
            }
            return false;
        }

取自OnTap listener implementation