防止按钮连续点击
其实实现很简单
共通方法:
- public class Utils {
- private static long lastClickTime;
- public static boolean isFastDoubleClick() {
- long time = System.currentTimeMillis();
- long timeD = time - lastClickTime;
- if ( 0 < timeD && timeD < 500) {
- return true;
- }
- lastClickTime = time;
- return false;
- }
- }
按钮点击时:
- public void onClick(View v) {
- if (Utils.isFastDoubleClick()) {
- return;
- }
- }
这样所有按钮在500毫秒内不能同时起效。
针对调时间做了一点改进
long timeD = time - lastClickTime;
0 < timeD
转自:http://kewell2004.iteye.com/blog/1545783