Disable Button after click

by pabbot » Sat, 12 Mar 2011 02:54:05 GMT

Sponsored Links
 Hi all,

In my application, when I click on a button that inserts a record on
the database and closes the Activity, sometimes it takes long to close
that Activity and some users are clicking on the Button twice. That
causes that the record is inserted twice in the database.

Is there any way of avoiding this behavior?

Thanks in advance!


Re: Disable Button after click

by Cliff Davies » Sat, 12 Mar 2011 02:58:53 GMT

 Set a boolean variable when the button has been pressed and check the
boolean is false in the on click listener so that you don't process it once
it's already been clicked


Sponsored Links

Re: Disable Button after click

by TreKing » Sat, 12 Mar 2011 03:03:36 GMT


Just disable the button when it's clicked, especially if you're closing the
Activity anyway.

TreKing < http://sites.google.com/site/rezmobileapps/treking> ; - Chicago
transit tracking app for Android-powered devices


Re: Disable Button after click

by Justin Anderson » Sat, 12 Mar 2011 03:07:01 GMT

 *> Is there any way of avoiding this behavior?*

Yes. Disable the button.
 http://developer.android.com/reference/android/widget/TextView.html #setEnabled%28boolean%29

Justin Anderson
MagouyaWare Developer


Re: Disable Button after click

by Sourav Howlader » Sat, 12 Mar 2011 04:24:01 GMT

 As soon as the button is clicked, set  button.setEnable(false);
  This will disable the button and will avoid from double clicking it.


Other Threads

1. Hide Activity

   I want to show a progress dialog, while I check something in the
background and display a message finally and exit the app. Can I hide
the Activity in the background? I tried using
android:theme="@android:style/Theme.NoDisplay" in the manifest file,
but the window shows up when I show the progress dialog or the

Thank you,


2. sending email with a file attached that is not on sdcard

I have a voice messaging app that needs to send an email with the
audio file attached when user records and presses send. I dont want to
have the user see a mail client and push send in it. He's already
aware my app is going to send an email and has pressed a send button
in the app. The audio file is in the app folder area, not on the

Using ACTIONSEND and Intent.EXTRA_STREAM (a) requires the file to be
on sdcard and (b) displays a mail client UI. I found a library called
javamail_lbmod.jar but it is over 1MB large; I feel thats overkill for
what I need.

Anyone know of a small library or other solution for my issue. I could
live with the sdcard requirement if I could just suppress the mail
client UI.


3. query button on phone

4. Akhirnya....CM5 for Dream/Magic -> yup, its Eclair!!!

5. How to detect key held down

6. 14-year-old Android Developer:

7. Update sold Wts milestone murmer