自定义一个NoDoubleClickListener,继承自OnClickListener: 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); } } protected abstract void onNoDoubleClick(View v); } 在设置点击事件时用NoDoubleClickListener替换OnClickListener,并且实现方法onNoDoubleClick替换onClick即可: btnPay.setOnClickListener(new NoDoubleClickListener() { @Override protected void onNoDoubleClick(View v) { startPay(); } }); }
时间: 2024-10-28 14:42:58