Android prevents repeated clicks on controls and multiple clicks at the same time
Introduction
In a mobile phone interface, users often click multiple controls at the same time, and often click multiple controls in a short period of time, which will cause various bugs.
Prevent Multiple widgets from being clicked
You only need to add such a line of code to the parent container in the xml file:
Android: splitMotionEvents = "false"
For example, adding this line to the LinearLayout below indicates that only one element of LinearLayout can be clicked at a time, and other elements cannot be clicked.
Android: layout_width = "match_parent"
Android: layout_height = "wrap_content"
Android: layout_margin = "@ dimen/dp10"
Android: splitMotionEvents = "false"
Android: background = "@ drawable/shape_frame_black"
Android: orientation = "vertical">
Prevents multiple clicks on a control
We only need to add a flag to determine whether the interval between the two clicks is greater than a fixed value. We can define this fixed value.
Private long lastClickTime;
/**
* Prevent repeated clicks
* @ Return
*/
Private boolean isFastDoubleClick (){
Long time = System. currentTimeMillis ();
Long timeD = time-lastClickTime;
If (0 <timeD & timeD <500 ){
Return true;
}
LastClickTime = time;
Return false;
}