1. 程式人生 > >android防止控制元件多次點選

android防止控制元件多次點選

android防止空間多次點選:

package com.heinqi.mesumeguide.util;

import android.os.Handler;
import android.view.View;

public class DoubleClick {

	//方法一
	public static void ForbidDoubleClick(final View view) {
		view.setClickable(false);
		new Handler().postDelayed(new Runnable() {

			@Override
			public void run() {
				view.setClickable(true);
			}
		}, 500);
	}

	//方法二
	public static long lastClickTime;

	public static boolean ForbidDoubleClick() {
		long time = System.currentTimeMillis();

		if ((time - lastClickTime) < 800) {
			return false;
		}

		lastClickTime = time;
		return true;
	}
}