用法如下
/**
* 项目名称:mobile_android
* 创建者: 郑伟
* 创建时间:2017/12/22 下午4:35
* 功能简介:用于防止View重复点击
*/
public abstract class NoDoubleClickListener implements View.OnClickListener {
public static final int MIN_CLICK_DELAY_TIME = 1000;
private long lastClickTime = 0;
@Override
public void onClick(View v) {
long currentTime = Calendar.getInstance().getTimeInMillis();
if (currentTime - lastClickTime > MIN_CLICK_DELAY_TIME) {
lastClickTime = currentTime;
onNoDoubleClick(v);
}
}
public abstract void onNoDoubleClick(View view);
}