防止按鈕連續點擊
其實實現很簡單
共通方法:
- 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
