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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:21:20+00:00 2026-06-04T08:21:20+00:00

I try to use this code to prevent multi-click in ImageView but it doesn’t

  • 0

I try to use this code to prevent multi-click in ImageView but it doesn’t help.

    Boolean isClicked = false;
    @Override
    public void onClick(View v)
    {
        if (v == imgClick && !isClicked)
        {
                      //lock the image
            isClicked = true;
            Log.d(TAG, "button click");

            try
            {
                //I try to do some thing and then release the image view
                Thread.sleep(2000);
            } catch (InterruptedException e)
            {
                e.printStackTrace();
            }
            isClicked = false;
        }

    }

In the log cat, I can see 5 lines “button click” when I click on ImageView for 5 times as quickly as possible. I can see the log cat print the first line, wait for a while (2 seconds) and then print the next line.
I think when I click the ImageView, the fired event is moved to queue in order, isn’t it?. So how can I stop that?

I also try to use setEnable() or setClickable() instead of isClicked variable but it doesn’t work too.

  • 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-04T08:21:21+00:00Added an answer on June 4, 2026 at 8:21 am

    Just try this working code

        Boolean canClick = true; //make global variable
       Handler  myHandler = new Handler();
    
    @Override
    public void onClick(View v)
    {
        if (canClick)
        {
    
           canClick= false;   //lock the image
           myHandler.postDelayed(mMyRunnable, 2000);
    
           //perform  your action here
    
        }
    
    }
    
    /* give some delay..*/
        private Runnable mMyRunnable = new Runnable()
        {
            @Override
            public void run()
            {   
    
             canClick = true;
             myHandler.removeMessages(0);
            }
         };
    
    
    Instead of sleeping in 2 seconds, I use some task like doSomeThing() method (has accessed UI thread), and I don't know when it completed. So how can I try your way?
    

    //I referred this android link. You can handle thread more efficiently but i hope below code will work for you..
    //you try this and

     Boolean canClick = true; //make global variable
    public void onClick(View v) {
            if(canClick){
    
              new DownloadImageTask().execute();
            }
        }
    
            private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
    
    
                protected Bitmap doInBackground(String... urls) {
                     Log.d("MSG","Clicked");
                     canClick =false;
                     //perform your long operation here
    
                    return null;
                 }
    
                 protected void onPostExecute(Bitmap result) {
                     canClick =true;
                 }
             }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I try to update my profile image and use this code: $connection->post('account/update_profile_image', array('image' =>
I try to use the boolean in my class and get this message reference
I try to use this mapping : @Entity @Table(name=ecc.\RATE\) @Inheritance(strategy=InheritanceType.SINGLE_TABLE) @DiscriminatorColumn(name=DISCRIMINATOR, discriminatorType= DiscriminatorType.STRING) public
When I try to use this in my Javascript prototype like so: Array.prototype.sample =
I get this error when I try to use time_ago_in_words : Comparison of String
i am having this problem try to use the cocos2d CCScrollLayer I have added
I have this implementation with fusion table layers where I try to use the
Try to download this page: http://www.4shared.com/get/B4AgMkcw/cookies.html I can use wget/firefox to get the whole
This article on MSDN states that you can use as many try catch blocks
I try use string as a regular expression pattern but I've following errors PHP

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.