Android solves the problem of repeatedly clicking buttons
- 2020-11-30 08:31:38
- OfStack
To prevent users or test MM from clicking wildly on an button, write a method to prevent buttons from clicking continuously. The concrete example code is as follows:
public class BaseActivity extends Activity {
protected boolean isDestroy;
// Prevents repeated clicking on the set flag that involves clicking on the open other Activity , the flag is set to false In the onResume Event set to true
private boolean clickable=true;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
isDestroy=false;
requestWindowFeature(Window.FEATURE_NO_TITLE);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
@Override
protected void onDestroy() {
super.onDestroy();
isDestroy=true;
}
@Override
protected void onResume() {
super.onResume();
// Set the click flag to clickable each time you return to the interface
clickable=true;
}
/**
* Is it currently available to click
* @return
*/
protected boolean isClickable(){
return clickable;
}
/**
* The lock click
*/
protected void lockClick(){
clickable=false;
}
@Override
public void startActivityForResult(Intent intent, int requestCode, Bundle options) {
if(isClickable()) {
lockClick();
super.startActivityForResult(intent, requestCode,options);
}
}
}
Through 1 section of simple code to introduce Android to solve the button click problem, I hope you like it.