The standard way to avoid multiple clicks is to save the last clicked time and avoid the other widget clicks within a preferred time private long lastPressesTime; @Override
Some times user may clicks multiple times on same widget, at that time App misleads and gives crassh/un expected behaviour to user.
We can resolve this by using the below code
public void onClick(View v) {
// Preventing multiple clicks, using threshold of 1 second
if (SystemClock.elapsedRealtime() - lastPressesTime < 1000) {
return;
}
lastPressesTime = SystemClock.elapsedRealtime();
switch(v.getId())
{
case R.id.widget1:
break;
case R.id.widget2:
break;
}
}
How to get an image resource by it's name in android?
What is NetworkOnMainThread Exception?
How to convert milli seconds to hours, minutes and seconds in Android?
FragmentPagerAdapter deprecated, Since API 27.1.0 FragmentPagerAdapter is deprecated.
How to Exit android app on back pressed?
How do i load image from drawable folder in Jetpack Compose?
Symmetric vs Asymmetric Encryption in Android Server - RRutors
Android Studio project R can't find
What is the Different Between val and var in Kotlin?
What is ANR? How to avoid and resolve it?
How to validate email address in Android with Kotlin?
What is ANR in android?
Hide/Disable soft keyboard on Activity launch: Android
Fix Behavior Subclass BottomSheetBehavior Exception - RRutors
How do I check in SQLite whether a table exists?
What is Application?
How can i comment inside xml file in android studio?
Open PDF in Google Drive with Intent in Android - RRutors
How to Generate signed apk with android studio
What is Intent? What is the difference between an implicit intent and an explicit intent?
What is Context?
How to get a contact image using a phone number in android?
How do I generate random numbers in Dart?
Extract Date and Time from Long Type Variable - RRutors
What is "shared preferences" in Android ?
Fix Duplicate Files in APK Build.gradle Issue - RRutors
What is Android Fragments?
ERR_ACCESS_DENIED in Android Webview with sdk 30
Fix Error: Use JsonReader.setLenient(true) for Malformed JSON
How to avoid multiple button click at same time in android?
Invoke-customs are only supported starting with android 0 --min-api 26
Add Jar/Library Files as Dependency in Android Studio
How to find Android Device UDID or unique ID?
How to reduce APK package size?
How to Get bitmap from drawable: Android
How to start a new activity on button click
How To Set Text Color Programmatically Android TextView?
How to install/ uninstall apk by command line ADB
Emulator: emulator: ERROR: Can't find 'Linux version ' string in kernel image file: Andr
How to Use Deprecated Handler() in Android - RRutors Guide