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. Application Testing Group anyone?

Would anyone be interested in setting up an application testing group
where various beta apps could be tested by individuals on DIFFERENT
phone models to help ensure the stability of new apps + provide
concise feedback to the developer...
I ran into this problem because for some types of apps the emulator
setting dont seem to be a good enough and reliable indication of
whether the app will ACTUALLY work on different phones...

Anyone interested?
It should be easy enough to get to the downloads to share and I would
be happy to provide feedback on other's apps for a little more
constructive + informed criticism of my own, espcially infroming of
exceptions more descriptively



2. Android to Add Next 500M Mobile Web Users in India?



3. app "not yet shipped"? help

4. Linkify colors

5. Android Party shuffle

6. User Identity

7. Rotate floating AVD