Android prevents repeated clicks on controls and multiple clicks at the same time

Source: Internet
Author: User

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;
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.