方案一
- view.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- new ContinuousClick().start();
- if (ContinuousClick.IsAlive >= 5) {
- Log.e(TAG,"连续点击了5次");
- }
- }
- });
- static class ContinuousClick extends Thread {
- public static volatile int IsAlive = 0;
- @Override
- public void run() {
- IsAlive++;
- try {
- Thread.sleep(3000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- if (IsAlive > 0) {
- IsAlive--;
- }
- super.run();
- }
- }
方案二:转载:http://www.jianshu.com/p/c94948fe30a1
private static final String PACKAGE_NAME_LAUNCHER = "com.android.launcher3";
private int mSecretNumber = 0;
private static final long MIN_CLICK_INTERVAL = 600;
private long mLastClickTime;
// click logo button 10 times continuously to open com.android.launcher3
findViewById(R.id.logo).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
long currentClickTime = SystemClock.uptimeMillis();
long elapsedTime = currentClickTime - mLastClickTime;
mLastClickTime = currentClickTime;
if (elapsedTime < MIN_CLICK_INTERVAL) {
++mSecretNumber;
if (9 == mSecretNumber) {
try {
Intent intent = getPackageManager().getLaunchIntentForPackage(PACKAGE_NAME_LAUNCHER);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
} catch (Exception e) {
Log.i(TAG, e.toString());
}
finish();
}
} else {
mSecretNumber = 0;
}
}
});