兔子--多击事件

package com.example.myclickmore;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.SystemClock;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends Activity {
	private Button btn;
	private long[] mHits = new long[3];
	int i = 0;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		final Intent intent = new Intent();
		btn = (Button) findViewById(R.id.button1);
		btn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				System.out.println(+mHits.length);
				i++;
				Log.i("i", i + "");
				btn.setText(i + "");

				// System.arraycopy实现的功能数组的内部元素自拷贝,
				// 每次mHits[0]都被mHits[1]覆盖
				// 从而判断是否是按连击事件处理。
				// src the source array to copy the content.
				// srcPos the starting index of the content in src.
				// dst the destination array to copy the data into.
				// dstPos the starting index for the copied content in dst.
				// length the number of elements to be copied.

				System.arraycopy(mHits, 1, mHits, 0, mHits.length - 1);
				mHits[mHits.length - 1] = SystemClock.uptimeMillis(); // 系统开机时间
				btn.setText(i + SystemClock.uptimeMillis() + "");
				if (mHits[0] >= (SystemClock.uptimeMillis() - 500)) {
					Toast.makeText(MainActivity.this, "这就是传说中的多击事件",
							Toast.LENGTH_LONG).show();

					intent.setClass(MainActivity.this, MainActivity1.class);
					startActivity(intent);

				}

			}
		});

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

IT兔子123

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值