如何实现双击在安卓 [英] how to implement double click in android
问题描述
我做的,我希望显示在单次触摸的特定信息以及使用android.How双触控另一条消息,我可以实现它的一个项目。
我的样品code低于
如果(firstTap){
thisTime = SystemClock.u`enter code here`ptimeMillis();
firstTap = FALSE;
}其他{
prevTime = thisTime;
thisTime = SystemClock.uptimeMillis();
//检查thisTime大于prevTime
//只是柜面系统时钟复位至零
如果(thisTime> prevTime){
//检查时间是我们最大延迟时间内
如果((thisTime - prevTime)< = DOUBLE_CLICK_MAX_DELAY){
//我们已经检测到双击!
Toast.makeText(AddLocation.this,枪王DETECTED !!!,Toast.LENGTH_LONG).show();
//使你的逻辑HERE !!!!
}其他{
//否则重置firstTap
firstTap = TRUE;
}
}其他{
firstTap = TRUE;
}
}
返回false;
你为什么不使用长preSS事件insted的同时提交您的UI。 阅读答案在这里,我强烈推荐使用此功能。
或者如果它无论如何你想实现你有两个选择,一个是<一个href="http://stackoverflow.com/questions/5191456/how-can-i-place-double-click-event-on-imageview-in-android">this使用布尔 二是使用手势监听。
I am doing a project in which i want to display a particular message on single touch and another message on double touch using android.How can i implement it.
My sample code is below
if(firstTap){
thisTime = SystemClock.u`enter code here`ptimeMillis();
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(AddLocation.this, "DOUBLE TAP DETECTED!!!", Toast.LENGTH_LONG).show();
//PUT YOUR LOGIC HERE!!!!
}else{
//Otherwise Reset firstTap
firstTap = true;
}
}else{
firstTap = true;
}
}
return false;
Why dont you use Long Press event insted while its Recommanded UI. Read Answer Here , I strongly recommand to use this.
Or if its anyhow you want to implement you have two options , one is this using boolean and second is using Gesture Listener.
这篇关于如何实现双击在安卓的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!