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. InstrumentationTestCase.sendKeys() fails on headless emulators


before reporting this as a bug, I thought I'd ask here (I also posted
on stackoverflow with no reply so far, but the Google developers don't
seem to be actively posting there anyway --

So the problem is:
We run a build server in our company on a headless Linux, so we have
to start the emulator with the -no-window flag when running the
instrumentation tests. When this flag is set, however, the
InstrumentationTestCase.sendKeys() method fails -- not with an
exception, but there is an obscure message in the device log:

Permission denied: injecting key event from pid 646 uid 10026 to
window Window{43d55100 paused=false} owned by uid 1000

this works fine on a "normal" emulator which does have a window.

We already tried fumbling with the INJECT_EVENTS permission, process
affinity and sharedUserId, but nothing works.

This basically makes our test suite useless on a build server, which
are typically headless. Is this a bug or are we missing something?



2. Adding a tabhost in viewflipper


I am new to this platform and already starting to love it. I am work
on a UI for a project which uses the tabhost to display two separate
activities using a TabActivity class. This works ok.

Now i would like to add a viewflipper to the equation. I am trying to
add the tabhost widget to the viewflipper using the addView() method.
        public class Main extends TabActivity {

        public void onCreate(Bundle savedInstanceState) {

                TabHost host = getTabHost();
                                new Intent(this, First.class)));
                                .setContent(new Intent(this, Second.class)));

               Button btn1 = new Button(this);
               btn1.setText("Notin' still dey happen");

               flipper = new ViewFlipper(this);



The main motive is to an application with two activities all tabbed.
The viewflipper will then flip between these two activities. I am
thinking an alternative will be to use xml layout to hold the tabhost
and just include it in the view.
I am avoiding it for now because that would mean me writing the codes
for the two classes again.

To round all this up, is there a way to include a tabhost in a

New Guy


3. integrating skyhook in android application

4. About NexusOne Android2.1 contacts problem

5. statelistdrawable in xml

6. switch soundtracks of an mp4 file

7. Access to AT command interface of GSM radio