码迷,mamicode.com
首页 > 其他好文 > 详细

Button--防止button多次点击

时间:2016-09-21 21:27:42      阅读:121      评论:0      收藏:0      [点我收藏+]

标签:

 

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

//代码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多次点击

标签:

原文地址:http://www.cnblogs.com/awkflf11/p/5894153.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!