SohailAziz
SohailAziz

Reputation: 8034

How to disable/enable progress dialog button

I want to show a progress dialog which will only show "close" button when desired e.g when progress value reached to its max value. On that "close" button I want to dismiss the dialog. I made progress dialog with negative button and I can dismiss it when user click on it but I don't want "close" button be visible/enable all the time just when I want or when progress completed.

Thanks.

Upvotes: 5

Views: 4472

Answers (2)

ScottieMc
ScottieMc

Reputation: 686

To build off of Guillaume's comment and Karim's answer, you can hide/show or enable/disable a button on a ProgressDialog like so:

ProgressDialog dlg = new ProgressDialog(this);
dlg.setButton(ProgressDialog.BUTTON_NEUTRAL, 
              "Close", 
              new DialogInterface.OnClickListener() {                   
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            //button click stuff here
                        }
                    });

dlg.show();    
dlg.getButton(ProgressDialog.BUTTON_NEUTRAL).setEnabled(false);
//or alternatively
//dlg.getButton(ProgressDialog.BUTTON_NEUTRAL).setVisibility(View.INVISIBLE);

You can hang onto the Button to enable later, once your task completes. Just be sure to call getButton after you call show.

Upvotes: 5

Karim Varela
Karim Varela

Reputation: 7652

You should build a custom dialog with a ProgressBar and a Button. Then use Button.setVisibility(View.VISIBLE) and Button.setVisibility(View.INVISIBLE)

Upvotes: 1

Related Questions