Multiple Click events
Multiple-click event principle: If the last click event is less than a certain time interval from the first click event, it is considered to be a multiple click event when it is less than.
Android source code to achieve the effect:
1 Importandroid.app.Activity;2 ImportAndroid.os.Bundle;3 ImportAndroid.os.SystemClock;4 ImportAndroid.view.View;5 6 Public classMainactivityextendsActivity {7 8 @Override9 protected voidonCreate (Bundle savedinstancestate) {Ten Super. OnCreate (savedinstancestate); One Setcontentview (r.layout.activity_main); A } - //sets a 3-bit array. You need to click a few times to set up a few arrays - Long[] mHITs =New Long[3]; the Public voidOnClick (View v) { - //the elements of the copied array start at the 1th position, the destination address is the No. 0 position, the length of the copy is an array length-1 -System.arraycopy (mhits, 1, mhits, 0, Mhits.length-1); - //assigns a value to the last position of the array +MHITS[MHITS.LENGTH-1] =Systemclock.uptimemillis (); - //determines whether the difference between the time of the first position of the array and the current time is less than 500 milliseconds, which, if less, is considered a multiple-click event. + if(Mhits[0] >= (Systemclock.uptimemillis ()-500)) { ASystem.out.println ("---------------------clicked three times----------------------------"); at } - } -}
The source of Android development: the principle and implementation of multiple click events