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. android.database.StaleDataException: Access closed cursor

*android.database.StaleDataException: Access closed cursor*

I have activity A and I used managedQuery in Activity A. I have an adpater
which extends from BaseAdapter. In GetView I access the mcursor to get

If I click a button on Activity A it goes to B, A---> B

The problem arises when I am in activity B *and it's visible(B), the error
is thrown from Acitivity A. *

I dont understand why I get the error from Activity A. Activity B is visible
now and A is in background.

There was a post already on this group with similar error but there was no

I was hoping if someone encountered this and found a solution.

Thanks in advance for your response.


2. HTC Incredible suffering a reset while service running.

Beta tester has reported that while my service is running, the phone
reboots itself. Two beta testers have both reported this, both on the
HTC Incredible.

I can think of what I would do to cause a soft reset if I were trying,
which I'm not. After 5-10 minutes or about 1000 files downloaded, the
phone resets as if it were just powered up.

I am aware that what the service is doing probably puts some amount of
stress on the phone - downloading 1000s of small files and writing
them to the storage card. But, as far as I can tell, memory usage
should be fairly flat and is not monotonically increasing. I am not
able to cause a similar crash on my wimpy G1 nor on a 2.1 emulator
even after hours of similar conditions.

One of them has sent me a log from XtraLogic Log Collector. It had
nothing useful and doesn't seem to show anything before the crash.

Can anyone give me some advice on how to track this down?

Does anyone know, in general, what would cause a reset on an HTC

The only suspicion I would go on is some sort of memory overrun. I
think that would kill the service before it brought the phone down,
but who knows.



3. Trouble with pendingIntent

4. recognizing gpio buttons in userspace

5. Fwd: Touchscreen support for 7 Inch LCD panel

6. Crashing under Android 2.2. APIs update soon?

7. Finger swipe in Android API level 3 (OS 1.5) ?