1 package com.example.administrator.mystudent.MoreClick; 2 3 import android.os.SystemClock; 4 import android.support.v7.app.AppCompatActivity; 5 import android.os.Bundle; 6 import android.view.View; 7 import android.widget.TextView; 8 import android.widget.Toast; 9 10 import com.example.administrator.mystudent.R; 11 12 public class MoreClickActivity extends AppCompatActivity { 13 private TextView tv_name; 14 @Override 15 protected void onCreate(Bundle savedInstanceState) 16 { 17 super.onCreate(savedInstanceState); 18 setContentView(R.layout.activity_more_click); 19 20 tv_name= (TextView) findViewById(R.id.tv_name); 21 tv_name.setOnClickListener(new View.OnClickListener() 22 { 23 //需要监听几次点击事件数组的长度就为几 24 //如果要监听双击事件则数组长度为2,如果要监听3次连续点击事件则数组长度为3... 25 long[] mHints = new long[3];//初始全部为0 26 @Override 27 public void onClick(View v) 28 { 29 //将mHints数组内的所有元素左移一个位置 30 System.arraycopy(mHints, 1, mHints, 0, mHints.length - 1); 31 //获得当前系统已经启动的时间 32 mHints[mHints.length - 1] = SystemClock.uptimeMillis(); 33 if(SystemClock.uptimeMillis()-mHints[0]<=500) 34 Toast.makeText(getApplicationContext(),"当你点击三次之后才会出现", Toast.LENGTH_SHORT).show(); 35 } 36 }); 37 } 38 }