自定義一個NoDoubleClickListener
,繼承自OnClickListener
:ide
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); }
使用code
buttn.setOnClickListener(new NoDoubleClickListener() { @Override protected void onNoDoubleClick(View v) { //點擊事件後的邏輯事件 } });