点击间隔时间控制
为了避免在短时间内点击多次响应同一事件的工具类处理方法
import android.view.View;
/**
* 防止按钮连续点击
* Created by ${Dota.Wang} on 2017/10/19.
*/
public class DoubleClickUtils {
private static final int MIN_CLICK_DELAY_TIME = 1000;
private static long lastClickTime;
public static boolean isFastDoubleClick() {
long time = System.currentTimeMillis();
long timeD = time - lastClickTime;
if (0 < timeD && timeD < 1000) {
return true;
}
lastClickTime = time;
return false;
}
public static boolean isFastDoubleClick(View view) {
final int time_key = view.getId();
Object object = view.getTag(time_key);
long currentTime = System.currentTimeMillis();
view.setTag(time_key, currentTime);
if (object != null) {
long lastTime = (long) object;
long deltaTime = currentTime - lastTime;
if (deltaTime > 0 && deltaTime < 1000) {
return true;
}
}
return false;
}
}