Android 防止重复点击
1.第一种方式:
private static final int MIN_DELAY_TIME = 2000; // 两次点击间隔不能少于2000ms
private static long lastClickTime = System.currentTimeMillis();
public static boolean isFastClick() {
boolean flag = true;
long currentClickTime = System.currentTimeMillis();
if ((currentClickTime - lastClickTime) <= MIN_DELAY_TIME) {
flag = false;
}
lastClickTime = currentClickTime;
return flag;
}
使用如下:
if (isFastClick()){
//判断重复点击 true
}else{
//不是重复点击 false
}
第2种方式:
private long oldClickTime = 0; long clickTime = System.currentTimeMillis(); if (clickTime - oldClickTime < 800) return; oldClickTime = clickTime;
使用如下:
第3种方式:
private static final int MIN_DELAY_TIME = 500; // 两次点击间隔 private static long lastClickTime = 0L; public static boolean isFastClick() { boolean flag = true; long currentClickTime = System.currentTimeMillis(); if ((currentClickTime - lastClickTime) >= MIN_DELAY_TIME) { flag = false; } lastClickTime = currentClickTime; return flag; }
使用如下:
if (isFastClick()) { Log.d(TAG, "onClick"); return; }
Android中防止重复点击的小技巧_android 防重复点击-CSDN博客
原文地址:https://blog.csdn.net/qq_33386162/article/details/140611654
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!