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. How do I change the textColorPrimary in a theme?

I'm changing the theme of an activity in onCreate using setTheme (I'm
doing that even before calling super.onCreate(), as this is supposed
to be more reliable).

It does work in the sense that it changes the background and
foreground colors. However, my layout has a few elements that use
styles like textAppearanceLarge. Now Android's textAppearanceLarge
internally uses the textPrimaryColor - which is still unchanged by my

I tried to override the primary text color in my theme, but that
doesn't seem to work.

Here is the crucial part of the theme:

<style name="Theme.MyApp.White">
   <item name="android:background">@android:color/white</item>
   <item name="android:textColor">#000000</item>

The background appears white, plain TextViews appear black... but
TextViews using textAppearanceLarge are white, and as such invisible
(white on white).

I tried things like this:

   <item name="android:ColorPrimary">#000000</item>
   <item name="android:textColorPrimary">#000000</item>
   <item name="android:attr/textColorPrimary">#000000</item>

But none of those do anything. What's the magic trick?


2. Modified Files in Linux kernel for android

Hi all,

New to android.....

Can any one tell me "what are the files needs to be changed
mandatorily in the linux kernel with respect to android to port to
other platforms??"

What are the major dependencies with respect to android porting to
other platform???

unsubscribe: android-kernel+unsubscr...@googlegroups.com

3. Why is it that moderators never accept my questions?

4. Widget inside a pre-existing application

5. Drawing 2D stuff on the screen in OpenGL over a 3D scene

6. Is there any way or tool to test NAND performance on my android phone

7. "can not be resolved to a type" errors while generating List View in Eclipse