long[] mHits = new long[3];public void treeClick(View v){/**
- arraycopy里面5個(gè)參數(shù)詳解
- 1.src the source array to copy the content. 拷貝的原數(shù)組 2.srcPos the starting index of the content in src. 是從源數(shù)組那個(gè)位置開(kāi)始拷貝 3.dst the destination array to copy the data into. 拷貝的目標(biāo)數(shù)組 4.dstPos the starting index for the copied content in dst. 是從目標(biāo)數(shù)組那個(gè)位置開(kāi)始去寫(xiě) 5.length the number of elements to be copied. 拷貝的長(zhǎng)度*///拷貝數(shù)組操作System.arraycopy(mHits, 1, mHits, 0, mHits.length-1); mHits[mHits.length-1] = SystemClock.uptimeMillis(); // 將離開(kāi)機(jī)的時(shí)間設(shè)置給數(shù)組的第二個(gè)元素,離開(kāi)機(jī)時(shí)間 :毫秒值,手機(jī)休眠不算 if (mHits[0] >= (SystemClock.uptimeMillis()-500)) { // 判斷是否多擊操作 System.out.println("多擊了..."); }}
原理圖:long數(shù)組mHits 里面的值變化俐载。
圖可能看起來(lái)有點(diǎn)難理解,下面再解釋一下。
第一擊:即第一次點(diǎn)擊的時(shí)候孵淘,記錄第一次點(diǎn)擊的時(shí)間比如說(shuō)700ms,賦值到mHits[2]中保存起來(lái)
第二擊:把mHits 數(shù)組里面的值更新一下袖裕,即mHits[1]保存第一次點(diǎn)擊的時(shí)間(700ms)躺率,mHits[2]保存第二次點(diǎn)擊的時(shí)間(900)。
第三擊:同第二擊棵逊,把mHits 數(shù)組里面的值再次更新伤疙。判斷如果mHits[0]里面的值(第一次點(diǎn)擊的時(shí)間)大于現(xiàn)在的時(shí)間減去500ms,代表這個(gè)控件在500ms中點(diǎn)擊了3次辆影,即三連擊徒像,多擊操作。
我語(yǔ)文不好蛙讥,解釋的盡力了锯蛀,望親們可以理解〈温或者提一些建議3Q旁涤、