首页 > 代码库 > Button--防止button多次点击

Button--防止button多次点击

 

=================================

//代码2
public abstract class NoDoubleClickListener implements OnClickListener {

public static final int MIN_CLICK_DELAY_TIME = 1000;
private long lastClickTime = 0;

public abstract onNoDoubleClick(View view);


@Override
public void onClick(View v) {
long currentTime = Calendar.getInstance().getTimeInMillis();
if (currentTime - lastClickTime > MIN_CLICK_DELAY_TIME) {
lastClickTime = currentTime;
onNoDoubleClick(v);
}
}
}


使用方法;给submitButton设置点击事件时用NoDoubleClickListener代替OnClickListener,并且实现方法onNoDoubleClick代替onClick即可,像这样:
//代码3
submitButton.setOnClickListener(new NoDoubleClickListener() {
@Override
public void onNoDoubleClick(View v) {
submitOrder();
}
});

Button--防止button多次点击