自定义一个NoDoubleClickListener
,继承自OnClickListener
:
public abstract class NoDoubleClickListener implements OnClickListener { //两次点击按钮之间的点击间隔不能少于2000毫秒 public static final int MIN_CLICK_DELAY_TIME = 2000; 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); }
使用
buttn.setOnClickListener(new NoDoubleClickListener() { @Override protected void onNoDoubleClick(View v) { //点击事件后的逻辑事件 } });