public abstract class CustomClickListener implements View.OnClickListener {
/**
* 此类用于防止按钮多次点击
*/
private long mLastClickTime;
private long timeInterval = 5000L;//5秒
public CustomClickListener() {
}
public CustomClickListener(long interval) {
this.timeInterval = interval;
}
@Override
public void onClick(View v) {
long nowTime = System.currentTimeMillis();
if (nowTime - mLastClickTime > timeInterval) {
// 单次点击事件
onSingleClick();
mLastClickTime = nowTime;
} else {
// 快速点击事件
onFastClick();
}
}
protected abstract void onSingleClick();
protected abstract void onFastClick();
}
使用方法:
button.setOnClickListener(new CustomClickListener() {
@Override
protected void onSingleClick() {
//单次点击
}
@Override
protected void onFastClick() {
//快速点击
}
});