How to disable/enable progress dialog button

android, progressdialog

Solution

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`.

Problem

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.

Original source