原地址:http://blog.csdn.net/a394268045/article/details/51548197
项目中遇到快速点击两次时,会出现两个相同界面,
解决办法:在父类activity中重写事件分发的方法dispatchTouchEvent()
原理:
当在activity中快速点击某个控件,时间间隔不超过300ms,此时activity拦截click事件,这是点击的view将得不到响应,代码如下:
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
if (ev.getAction() == MotionEvent.ACTION_DOWN) {
if (isFastDoubleClick()) {
return true;
}
}
return super.dispatchTouchEvent(ev);
}
public boolean isFastDoubleClick() {
long time = System.currentTimeMillis();
long timeD = time - lastClickTime;
lastClickTime = time;
return timeD <= 300;
}