Android有时候控件连续点击会引发一些问题,可采用如下策略避免,在utils内写一个工具方法,例如500ms或1s等内不允许连续点击。
private static final int CLICK_DELAY_TIME = 500;
private static long lastClickTime;
/**
* 防止button快速连点
*
* @return
*/
public static boolean isNotFastClick() {
boolean flag = false;
long currentClickTime = System.currentTimeMillis();
if ((currentClickTime - lastClickTime) >= CLICK_DELAY_TIME) {
flag = true;
}
lastClickTime = curClickTime;
return flag;
}
if (Utils.isNotFastClick()) {
//处理点击事件
}