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 3983584
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:39:57+00:00 2026-05-20T05:39:57+00:00

Hello I have one ImageButton with single image. I have added onclick event and

  • 0

Hello
I have one ImageButton with single image. I have added onclick event and normally it works fine.When Imagebutton is clicked my add entry function works.

Now when user continously clicks my imagebutton, My add entry functions executes that many times with same data. I want to prevent it. Such that, Imagebutton should not queue up to process next click event until my function gets executed completely.

I tried to myImageButton.setEnable(false) as soon as OnClick event executes. And Doing

myImageButton.setEnable(true) after my data entry function.

I also tried to put this code in myImageButton.isEnabled() but didnt work.

How to ignore such queued click events? Is there any other way (than setEnable()) to ignore/eat click processing?

I have checked by putting println statements that each click event is in sync…means all code executes in order.

EDIT

   private OnClickListener m_AddClickHandler = new OnClickListener()
    {
        public void onClick(View v)
        {
            if(m_bDoAdd)
            {
                m_bDoAdd = false;
                new AddTask().execute();
            }
            else
                logData("Add::OnClick::not clicked");
        }
    };
private class AddTask extends AsyncTask<Void, Void, Integer> 
    {
        @Override
        protected Integer doInBackground(Void... params) 
        {
            logData("doinbg, start"+m_bDoAdd);
            int iStatus =Add(m_data);
            logData("doinbg, start end, status="+iStatus+"flag="+m_bDoAdd);
            return iStatus;
        }

        @Override
        protected void onPostExecute(Integer result) 
        {
            logData("onpostExec, start"+m_bDoAdd);
            int iStatus = result;
            if (iStatus == 0)
            {
                Toast.makeText(getApplicationContext(), R.string.strAdded, Toast.LENGTH_SHORT).show();
            }
            else if (iStatus == 1)
            {
                Toast.makeText(getApplicationContext(), R.string.strAlreadyExists, Toast.LENGTH_SHORT).show();
            }
            else
            {
                Toast.makeText(getApplicationContext(), R.string.strAddFailed, Toast.LENGTH_SHORT).show();
            }

            m_bDoAdd = true;
            logData("onpostExec, end"+m_bDoAdd);
        }
    }

    void Add()
    {
       // Add info to db (takes few msecs)
    }

I am still not getting “Add::OnClick::not clicked” in log.

Any further clue?

  • 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-05-20T05:39:58+00:00Added an answer on May 20, 2026 at 5:39 am

    Try this inside onClick handler:

    myImageButton.setClickable(false);
    

    Update:

    This is how events work in Android:

    1. When user clicks a view an event is added to the event queue.
    2. Events are processed on EDT in a serial fashion: one after another.
    3. Event enqueuing and event dispatching is done in separate threads: processing an event does not prevent enqueuing a new event.

    A solution to your problem:

    1. You should process events as fast as possible and not block the EDT. This means you should do all long-running tasks (= your database operations) in the background thread – use AsyncTask for that.
    2. When you start a background task you should set a flag (backgroundWorkRunning) and clear it when done.
    3. When a new event is dispatched, first check the backgroundWorkRunning flag. Do nothing if flag is already set.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hello i have created one windows application in c# .net and its working fine
I have one requirement in C. char abc[]=hello; char hello[]=world; Using abc whether we
Hello every one I have wrote a simple code in html5 in which I
I have three button named(titled) hello, nothing, heaven and one label (IBOutlet UIlabel lab).
I have one div that should contain text and bellow it one image. I
Hello i have one array as below. $testArray = array ( '12 AM -
Hello I have one c++ Programming assignment question. I tried hard but somehow I
Hello I have one question about using genetic in correct way. please look at
Hello have following strange issue, can vertical center the menu text if it's one
Hello All I am using infragsitics tree view control.I have one stored procedure that

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.