Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 627
SohailAziz Avatar asked Dec 11 '12 22:12

SohailAziz


1 Answers

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.

like image 89
ScottieMc Avatar answered Oct 06 '22 22:10

ScottieMc