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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:08:19+00:00 2026-06-11T22:08:19+00:00

The code below is supposed to show a dialog box and then, depending on

  • 0

The code below is supposed to show a dialog box and then, depending on the state of the program, perform some animation (performed by the call to doseDownCourt()) when the dialog box is dismissed by clicking OK.

The problem is that the dialog box doesn’t immediately go away when dismissed–it stays on the screen, with the OK button in a “pressed” state (shaded blue), while the animation is being executed and displayed. The dialog box stays on screen until the animation is complete.

I’ve tried to change the order in which commands are executed, and also tried to use threads to make the animation wait for the dialog box to go away before it begins, but haven’t been able to get the behavior I want.

Any suggestions would be appreciated. Thanks.

    AlertDialog.Builder builder = new AlertDialog.Builder(this.getContext());       
    String message;
    Drawable puffle;
    Drawable dr;
    if (made == true) {
        message = "You made it!!!";
         dr = getResources().getDrawable(R.drawable.puff_happy);
    }
    else {
        message = "Aw, you missed. Better luck after your next dose!";
        dr = getResources().getDrawable(R.drawable.puff_confused);
    }
    builder.setMessage(message);        
    Bitmap bitmap = ((BitmapDrawable) dr).getBitmap();
    puffle = new BitmapDrawable(Bitmap.createScaledBitmap(bitmap, 200, 200, true));
    builder.setTitle(" ");
    builder.setIcon(puffle);
    builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {    
            alertDialog.dismiss();
            drawAll();      //put ball and shadow back with avatar
            doseDownCourt();    //call doseDownCourt in case multiple doses have been taken before a shot for each has been attempted               
        }
    });
    alertDialog = builder.create();
    alertDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    WindowManager.LayoutParams WMLP = alertDialog.getWindow().getAttributes();
    WMLP.y = -300;   //y position of dialog box
    alertDialog.getWindow().setAttributes(WMLP);
    alertDialog.show();
  • 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-11T22:08:20+00:00Added an answer on June 11, 2026 at 10:08 pm

    First of all you don’t have to dismiss your alert dialog in the onClickListener, because it will be closed by default.

    Second, try to run the drawAll and doseDownCourt functions in a background thread, and use a Handler to update your user interface.

    Take a look at the following documentation:

    http://developer.android.com/reference/android/app/Activity.html#runOnUiThread(java.lang.Runnable)

    http://developer.android.com/guide/components/processes-and-threads.html

    http://developer.android.com/reference/android/os/Handler.html

    So don’t run process’s that take lots of time on your main thread as your doing now, because onClick will be executed at the main thread.

    Edit: from the docs

    This code shows how to use a thread in the onClick function

    public void onClick(View v) {
        new Thread(new Runnable() {
            public void run() {
                Bitmap b = loadImageFromNetwork("http://example.com/image.png");
                mImageView.setImageBitmap(b);
            }
        }).start();
    }
    

    in your case you would change the code to something like this:

    public void onClick(View v) {
        new Thread(new Runnable() {
            public void run() {
                drawAll();
                doseDownCourt();
            }
        }).start();
    }
    

    But be careful because some things you may do in those 2 functions require to run on the UiThread, in that case you should use some kind of Handler.

    Rolf

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Code below doesn't work on any browser. It's supposed to show an alert box.
The code below is supposed to show a stack of three list boxes, each
My code below is supposed to display each question ($_POST[questionText]). For each question, it
Every time I run the code below it is supposed to come up with
I have the below code which is suppose to show a list of contact
I am using the code below to show and hide a div called map
The code below is supposed to get the next record when a button is
UPDATE: I've edited the code below to show what I was using when I
I suppose button should has Close title in the code below, but it has
I have this javascript code below that uses jquery, it is suppoed to be

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.