兔子--多击事件
16lz
2021-01-26
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;@Overrideprotected 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() {@Overridepublic void onClick(View v) {// TODO Auto-generated method stubSystem.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);}}});}@Overridepublic 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;}}
更多相关文章
- android 数组数据绑定到listview
- Android(安卓)View事件分发机制理解
- Android数组显示
- android EditText增加删除事件
- Android(安卓)设置DrawableRight和DrawableLeft 点击事件
- Android学习之键盘事件
- Android(安卓)实现事件监听的两个方法
- android 点击图片全屏展示效果
- android GestureListener