When users use Android applications, they often click the same button too quickly and multiple times. On the one hand, this is because the application or mobile phone is currently lagging. On the other hand, it may be because many applications do not set the selector or other button response methods when button clicking (for example, the button is enlarged when clicking the button, which is common in games), causing users to mistakenly believe that they did not click the current button. Of course, in addition to optimizing and setting the corresponding application to click selector, we can also do some other work. For example, the onClick event of the judgment button only responds once in the specified event segment (in the search function of the forum, we often see the setting that searches can be performed every 10 seconds, which reduces invalid network access to a certain extent and reduces server pressure. The same is true for APPs). As shown in the following code:
public final class AppUtils { private AppUtils() { } private static long mLastClickTime;// User judges the time of multiple clicks public static boolean isFastDoubleClick() { long time = (); if ((time - mLastClickTime) < 500) { return true; } mLastClickTime = time; return false; } } (new () { @Override public void onClick(View v) { if (()){ // Perform logical operations after click event } } });
Another way. . . . Create a new onclicklistener
public abstract class OnMultiClickListener implements { // The click interval between two button clicks cannot be less than 1000 milliseconds private static final int MIN_CLICK_DELAY_TIME = 1000; private static long lastClickTime; public abstract void onMultiClick(View v); @Override public void onClick(View v) { long curClickTime = (); if((curClickTime - lastClickTime) >= MIN_CLICK_DELAY_TIME) { // Reset lastClickTime to the current click time after the click interval has exceeded lastClickTime = curClickTime; onMultiClick(v); } } } (new OnMultiClickListener() { @Override public void onMultiClick(View v) { // Perform logical operations after click event } });
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.