Public classUtils {Private Static LongLastclicktime; Public StaticBoolean Isfastdoubleclick () {LongTime =System.currenttimemillis (); LongTimeD = time-Lastclicktime; if(0< TimeD && TimeD < -) {//the button is not valid in 500 milliseconds, so you can control the Quick click and adjust the frequency yourself . return true; } lastclicktime=Time ; return false; } } //Listener Button Call method Public voidOnClick (View v) {if(Utils.isfastdoubleclick ()) {return; } }
-----------------------------------------------------------------you can test it yourself, absolutely not.
Write a class
Package Com.example.teststyle;import Android.util.Log; Public classbuttonutil{Private Static LongLastclicktime =0; Private Static LongDIFF = the; Private Static intLastbuttonid =-1; /** * Determine the interval of two clicks, if less than 1000, is considered to be multiple invalid clicks * @return*/ Public StaticBoolean Isfastdoubleclick () {returnIsfastdoubleclick (-1, DIFF); } /** * Determine the interval of two clicks, if less than 1000, is considered to be multiple invalid clicks * @return*/ Public StaticBoolean Isfastdoubleclick (intButtonID) { returnIsfastdoubleclick (Buttonid,diff);} /** * To determine the interval of two clicks, if it is less than diff, it is considered multiple invalid click * @param diff * @return*/ Public StaticBoolean Isfastdoubleclick (intButtonID,Longdiff) { LongTime =System.currenttimemillis (); LongTimeD = time-Lastclicktime; LOG.V ("xxxx","Lastbuttonid ="+lastbuttonid+"ButtonID ="+ButtonID); if(Lastbuttonid = = ButtonID && lastclicktime>0&& TimeD <diff) {LOG.V ("Isfastdoubleclick","button trigger multiple times in a short time"); return true; } lastclicktime=Time ; Lastbuttonid=ButtonID; return false; }}
and then call
Public voidOnClick (View v) {//TODO auto-generated Method Stub if(Buttonutil.isfastdoubleclick (V.getid ())) {//control here, time to control.LOG.E ("-----> Show Click Time and Start time","Start Time"); Toast.maketext (Getapplicationcontext (),"Show Content", Toast.length_short). Show (); return } //start writing your own business logic ........... }
button click Frequency Control in Android