• About
  • Advertise
  • Privacy & Policy
  • Contact
Tech News, Magazine & Review WordPress Theme 2017
  • Home
    • Home – Layout 1
    • Home – Layout 2
    • Home – Layout 3
    • Home – Layout 4
    • Home – Layout 5
  • Review
  • Gaming
  • Gear

    Trending Tags

    • Best iPhone 7 deals
    • Apple Watch 2
    • Nintendo Switch
    • CES 2017
    • Playstation 4 Pro
    • iOS 10
    • iPhone 7
    • Sillicon Valley
  • Computers
  • Applications
  • Security
No Result
View All Result
  • Home
    • Home – Layout 1
    • Home – Layout 2
    • Home – Layout 3
    • Home – Layout 4
    • Home – Layout 5
  • Review
  • Gaming
  • Gear

    Trending Tags

    • Best iPhone 7 deals
    • Apple Watch 2
    • Nintendo Switch
    • CES 2017
    • Playstation 4 Pro
    • iOS 10
    • iPhone 7
    • Sillicon Valley
  • Computers
  • Applications
  • Security
No Result
View All Result
Overflow Archives
No Result
View All Result

Android Preventing Multiple Click On A Button – Kotlin

by
Home Android
Share on FacebookShare on Twitter

The Problem

Multiple clicks on a button bring a lot of unexpected/undesired output to the application’s functionality. We may have faced unexpected results when the button elements are clicked more than once before the click event responds. Recently I come through with a problem in an Android project, where the end-user faced multiple entries on his application. To prevent multiple clicks on a button in Android I have tried a way that helps me to avoid undesired results in the application flow.

Solution for Rapid Click

In this read, we will see how to prevent multiple clicks in the android mobile application. To provide a solution to this I went through the events log and noticed the user clicking the button continously. So always try to debug your codings to confirm whether it happened from the UI part or your code. If the problem exists in your code then fix it to avoid the problem.

android preventing multiple click on a button

At some point, we can’t expect the user to use the application with normal actions. They may use the application in the way they like to do. If the device is not responding properly then it will be the worst scenario for the app flow. The user may click it multiple times and the application may crash or open the screens multiple times or result in a big issue if it is related to the financial application.

When the application opens a screen multiple times it’s spoiling the flow of the application and the user experience, so it is important to stop such problems earlier.


Also Read: Android SearchView in ActionBar— Androidx and Kotlin


To prevent such problems it is important to handle the touch events in the application to prevent any unexpected results in data. Here I got a solution for such an issue by using the Handler. The handler is used to schedule messages and to be executed at some point, and to enqueue an action to be performed on a different thread. For more please refer below link

Solution for Rapid Click Issue on a Button

Please use the following in code where the button event is called, and do your logic inside the click event listener.

The above code is run when the button is clicked in the UI, and disable the button clicked event for the given interval time. After disabling the button it is a better way to notify the user that the button is disabled, so assign alpha to 0.5 to the button so the user will identify the button is disabled. The Handler() is the Kotlin method that helps to run threads with Runnable. In this example, I have used 1500 milli seconds as the interval for a better experience. You can use any value as you wish, but keep in mind that if the call is not to return or show any result the user needs to click it again, after this time interval the button should be enabled and the alpha set to 1.

That’s it, below is the outcome of this method. Here you can see that the button is disabled for some time when the click is listened to. And again it enabled to handle the click event. In this way, you can prevent the multiple click event easily.

android preventing multiple click on a button - result

Hint: You can use the progress bar if the click event takes some time to process. If it’s an API call, use full screen and non-cancelable dialogue to prevent user interaction with the UI. And disable the progress bar from the program to make further interactions; once the API call or background process is completed.

Also, read on Medium and support.

Tags: androidandroid button clickandroid button clicked multiple timeandroid button issueandroid codeandroid developmentandroid double clickandroid issueandroid multiple clickAndroid Preventing Double Clickandroid progressbarAndroid Rapid Click Preventing On A Button Using Handler - Kotlinandroid UI click call twicedouble clickkotlinPreventing Double Click on a Buttonprogressbarrapid click

Next Post
android searchview in actionbar - overflow archives

Android Searchview in Actionbar— Androidx and Kotlin

Comments 1

  1. Pingback: Android SearchView in ActionBar— Androidx and Kotlin - Overflow Archives

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recommended.

Parse Color Runtime In Unity 3D - Thumbnail

Change Color in Runtime – Unity 3D Tutorial

Android Splash Screen – Implement Perfect Splash Screen In Android

Android Splash Screen – Implement Perfect Splash Screen In Android

Trending.

Create Switch button UI in Unity 3D - overflow archives

Create Switch button UI in Unity 3D

Unity Gradient Effect UI Design Without Scripting | Simple Gradient Effects in Unity 3D

Unity Gradient Effect UI Design Without Scripting | Simple Gradient Effects in Unity 3D

How to Create circular progress bar in Unity 3D with rounded edge

Progress bar in Unity 3D

How to Create Progress bar in Unity 3D

Android Developer Options – Debugging Mode Options Explained – Part – I

Android Developer Options – Debugging Mode Options Explained – Part – I

Overflow Archives

© 2023 OverflowArchives.

Navigate Site

  • About
  • Advertise
  • Privacy & Policy
  • Contact

Follow Us

No Result
View All Result
  • Home
  • Review
  • Apple
  • Applications
  • Computers
  • Gaming
  • Gear
    • Audio
    • Camera
    • Smartphone
  • Microsoft
  • Photography
  • Security

© 2023 OverflowArchives.