/**
* ListView / RecyclerView item 防止重复点击处理方案
*/
public abstract class OnNoDoubleClickListener implements View.OnClickListener {
// 0.9秒内防止多次点击
public static final int MIN_CLICK_DELAY_TIME = 900;
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);
}
}
// 用户需要进一步实现
protected abstract void onNoDoubleClick(View v);
}
使用实例:
if (mOnItemClickListener != null) {
helper.itemView.setOnClickListener(new OnNoDoubleClickListener() {
@Override
protected void onNoDoubleClick(View v) {
mOnItemClickListener.onItemClick(v, position);
}
}
});
}