Tips for preventing repeated clicks in Android

Source: Internet
Author: User

Tips for preventing repeated clicks in Android

 

Set the time flag when you click to determine the time difference between two clicks, and customize a time interval SPACE_TIME. Make a judgment: when the time difference between two clicks is greater than SPACE_TIME, you can start to click. The Demo source code is as follows.

Tool: package com. plusub. renthostapp. util;/*** package: com. plusub. renthostapp. util * Created by noyet on 2015/11/26. */public class NoDoubleClickUtils {private static long lastClickTime; private final static int SPACE_TIME = 500; public static void initLastClickTime () {lastClickTime = 0;} public synchronized static boolean isDoubleClick () {long currentTime = System. currentTimeMillis (); boolean isClick2; if (currentTime-lastClickTime> SPACE_TIME) {isClick2 = false;} else {isClick2 = true;} lastClickTime = currentTime; return isClick2 ;}}
Usage:/*** order log */private View. OnClickListener logListener = new View. OnClickListener () {@ Override public void onClick (View view) {if (! NoDoubleClickUtils. isDoubleClick () {EventBus. getDefault (). post (new RefreshEvent (RefreshEvent. RefreshType. TYPE_LAND_ORDER_LOG, view. getTag ()));}}};

Mark it first. (Partition _ Partition)

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.