android:多次點選效果實現
阿新 • • 發佈:2018-11-06
public class MainActivity extends AppCompatActivity{ private final static int COUNTS = 5;//點選次數 private final static long VALIDTIME = 1300;//有效時間 private long[] mHits = new long[COUNTS]; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); findViewById(R.id.bt_my).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //mHits陣列元素左移一個位置 System.arraycopy(mHits, 1, mHits, 0, mHits.length - 1); //獲得當前系統已經啟動的時間 mHits[mHits.length - 1] = SystemClock.uptimeMillis(); if (mHits[0] >= (SystemClock.uptimeMillis() - VALIDTIME)) { Toast.makeText(MainActivity.this, "在" + VALIDTIME + "ms內," + "點選了" + COUNTS + "次", Toast.LENGTH_SHORT).show(); } } }); } }