Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8024531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:53:40+00:00 2026-06-04T22:53:40+00:00

A button triggers an action that should only be invoked once. The button is

  • 0

A button triggers an action that should only be invoked once. The button is disabled and hidden in the onClick handler before the action is performed:

someButton.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
        someButton.setEnabled(false);
        someButton.setClickable(false);
        someButton.setVisibility(View.GONE);
        performTaskOnce();
        }
    });

private void performTaskOnce() {
    Log.i("myapp", "Performing task");
    //Do something nontrivial that takes a few ms (like changing the view hierarchy)
}

Even though the button is disabled immediately, it is nonetheless possible to trigger multiple “onClick” events by tapping multiple times very quickly. (i.e. performTaskOnce is called multiple times). Is seems that the onClick events are queued before the the button is actually disabled.

I could fix the problem by checking in every single onClick handle whether the corresponding button is already disabled but that seems like a hack. Is there any better way to avoid this issue?

The problem occurs on Android 2.3.6, I cannot reproduce it on Android 4.0.3. But given the rarity of 4.x devices it is not an option to exclude older devices.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T22:53:42+00:00Added an answer on June 4, 2026 at 10:53 pm

    You could set a boolean variable to true when the button is clicked and set it to false when you’re done processing the click.

    This way you can ignore multiple clicks and not having to disable the button possibly avoiding annoying flickering of the button.

    boolean processClick=true;
    someButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if(processClick)
             {
            someButton.setEnabled(false);
            someButton.setClickable(false);
            someButton.setVisibility(View.GONE);
            performTaskOnce();
             }
            processClick=false; 
            }
        });
    
    private void performTaskOnce() {
        Log.i("myapp", "Performing task");
        //Do something nontrivial that takes a few ms (like changing the view hierarchy)
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my app, I have a button that triggers an action. However, I'd like
Looking to place a button that triggers a simple SMS script on my Tropo
I've created a button to trigger a pulse LED action on my app, but
I have a button which triggers the function inside set interval every 1 sec.
I have form with web browser component, there is a button which triggers page
I have a button on my page. When clicked it triggers an ajax call
I have created a Button with the following trigger: <Button Content=Test> <i:Interaction.Triggers> <i:EventTrigger EventName=Click>
<Canvas> <Button Name=b1 Content=Button/> <Rectangle Name=Mr1 Fill=Black> <Rectangle.Triggers> <EventTrigger SourceName=b1 RoutedEvent=Button.Click> <BeginStoryboard> <code.../> </BeginStoryboard>
i was wondering if it was possible to filter which action is invoked based
My son just discovered that he could hit my view's Done button, which flips

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.