long[] mHits = new long[3];public void treeClick(View v){/**
- arraycopy里面5個參數詳解
- 1.src the source array to copy the content. 拷貝的原數組 2.srcPos the starting index of the content in src. 是從源數組那個位置開始拷貝 3.dst the destination array to copy the data into. 拷貝的目標數組 4.dstPos the starting index for the copied content in dst. 是從目標數組那個位置開始去寫 5.length the number of elements to be copied. 拷貝的長度*///拷貝數組操作System.arraycopy(mHits, 1, mHits, 0, mHits.length-1); mHits[mHits.length-1] = SystemClock.uptimeMillis(); // 將離開機的時間設置給數組的第二個元素,離開機時間 :毫秒值,手機休眠不算 if (mHits[0] >= (SystemClock.uptimeMillis()-500)) { // 判斷是否多擊操作 System.out.println("多擊了..."); }}
原理圖:long數組mHits 里面的值變化。
圖可能看起來有點難理解,下面再解釋一下。
第一擊:即第一次點擊的時候,記錄第一次點擊的時間比如說700ms,賦值到mHits[2]中保存起來
第二擊:把mHits 數組里面的值更新一下,即mHits[1]保存第一次點擊的時間(700ms),mHits[2]保存第二次點擊的時間(900)。
第三擊:同第二擊,把mHits 數組里面的值再次更新。判斷如果mHits[0]里面的值(第一次點擊的時間)大于現在的時間減去500ms,代表這個控件在500ms中點擊了3次,即三連擊,多擊操作。
我語文不好,解釋的盡力了,望親們可以理解?;蛘咛嵋恍┙ㄗh3Q、