标签:
/**
* 模拟双击事件
* @author Kevin
*
*/
public class MainActivity extends Activity {
private long firstClickTime;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void onClick(View view) {
if (firstClickTime > 0) {// 发现之前点击过一次
if (System.currentTimeMillis() - firstClickTime < 500) {// 判断两次点击是否小于500毫秒
Toast.makeText(this, "双击啦!", Toast.LENGTH_SHORT).show();
firstClickTime = 0;//重置时间, 重新开始
return;
}
}
firstClickTime = System.currentTimeMillis();
}
}
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
long[] mHits = new long[3];// 数组长度表示要点击的次数
public void onClick(View view) {
System.arraycopy(mHits, 1, mHits, 0, mHits.length - 1);
mHits[mHits.length - 1] = SystemClock.uptimeMillis();// 开机后开始计算的时间
if (mHits[0] >= (SystemClock.uptimeMillis() - 500)) {
Toast.makeText(this, "是男人!!!", Toast.LENGTH_SHORT).show();
}
}
}
标签:
原文地址:http://www.cnblogs.com/liuyu0529/p/4921824.html