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. TabActivity and GLSurfaceView


In my app, i have a TabActivity with 2 tabs.
-Tab1 displays a web page (with WebViewClient)
-Tab2 displays contains a FrameLayout with 2 SurfaceViews :

The first SurfaceView contains the videocapture from the camera.
The second surfaceview is a GLSurfaceView.

The app works fine. I can switch from a tab to another.

But i want optimise my app :
When i switch from Tab2 to Tab1, i want to "pause" my render.
So in the Tab2 activity i reimplement

    public void onPause() {
        Log.i(LOGTAG, "onPause");

    public void onResume(){
        Log.i(LOGTAG, "onResume");

With this code, my render is stopped, but when i reswitch in the Tab2,
the GLSurfaceView is recreated (onSurfaceCreated(GL10 gl, EGLConfig
config) is called). The surface is re-created but i have never seen a
surfaceDestroyed call.

What's wrong?


2. What is drawable-hdpi, drawable-ldpi and drawable-mdpi ?



3. Regarding the surfaceview

4. How to disable pop up blocker in emulator 2.1

5. How to change target build on Android project?

6. Leaked Window changing orientation with SubMenu

7. SOLD WTS : Samsung Galaxy S Second