To prevent users or test mm from frantically clicking on a button:
Create a tool class Public classTools {Private Static LongLastclicktime; Public Static BooleanIsfastdoubleclick () {LongTime =System.currenttimemillis (); if(Time-lastclicktime < 500) { return true; } lastclicktime=Time ; return false; }} when using the Public voidOnClick (View v) {if(Tools. Isfastdoubleclick ()) {return; }}
Multiple clicks to achieve different functions:
//Implement a button listener implementation class, and define tag variables in the implementation class, and execute different methods depending on the value of the variable. //Example: intFlag = 0;//Defining Tag VariablesButton btn = (button) Findviewbyid (r.id.xxx);//Get buttonBtn.setonclicklistener (NewView.onclicklistener () {//Click Implementation class@Override Public voidOnClick (View v) {if(flag==0){ //Execution Method 1 (corresponding function 1)}Else if(flag==1){ //Execution Method 2 (corresponding function 2)}Else if(flag==2){ //Execution Method 3 (corresponding function 3)} flag= (flag+1)%3;//the rest gets looped to perform the above 3 different functions } });
Android Dev _ About click events