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

  • Home
  • SEARCH
  • 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 8358101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:41:32+00:00 2026-06-09T10:41:32+00:00

Why is the try block executed first, i want the colors to change first

  • 0

Why is the try block executed first, i want the colors to change first and then it should sleep fo 5000ms. i mean the system sleeps before the colors changes.
private OnClickListener CheckAnswer =new OnClickListener() {

    public void onClick(View arg0) {
        // TODO Auto-generated method stub

        disableButtons();
        Button incoming=(Button) arg0;
        if(incoming.getText().toString().equals(Q.getAnswer()))
        {
            incoming.setBackgroundColor(Color.GREEN);
            correct++;
            score+=15;
        }
        else 
        {
            incoming.setBackgroundColor(Color.RED);
            wrong++;
            if(C1.getText().toString().equals(Q.getAnswer()))
                C1.setBackgroundColor(Color.GREEN);
            else if(C2.getText().toString().equals(Q.getAnswer()))
                C2.setBackgroundColor(Color.GREEN);
            else if(C3.getText().toString().equals(Q.getAnswer()))
                C3.setBackgroundColor(Color.GREEN);
            modifyScore();

        }
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        questionGenerator();
    }
};`
  • 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-09T10:41:34+00:00Added an answer on June 9, 2026 at 10:41 am

    I’d guess because the properties of the view are updated, but the screen redraw is stuck behind your sleep. DO NOT sleep on the main thread.

    Instead create a Handler in the onCreate of your Activity and post a delayed Runnable to it.

    private Handler mHandler;
    protected void onCreate(Bundle savedInstanceState) {
        mHandler = new Handler();
    }
    ...
    private OnClickListener CheckAnswer = new OnClickListener() {
         public void onClick(View view) {
           // fix up view
           mHandler.postDelayed(new Runnable() {
               @Override
               public void run() {
                   questionGenerator();
               }
           }, 10000);
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently using two catch blocks after a try block. The first catches
So I have this function: (define (try try-block catch-block finally-block) ; Implements try/catch/finally like
I have the following piece of code in a try/catch block InputStream inputstream =
I am writing a stored procedure where i m using try catch block. Now
What is the closest you can get to a try-catch block in php4? I'm
If you wrap a call to HttpResponse.End within a try catch block, the ThreadAbortException
I'm trying to throw an exception (without using a try catch block) and my
My program compiles fine, but crashes everytime throw (not inside of a try...catch block)
Is it better, less expensive or more readable to use a try/catch block in
I was just wondering which would be cheaper, using a try catch block for

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.