Android Alert Dialog - how to hide the OK button after pressing it

I am developing an Android application.

I would like to hide the OK button after the user clicks it, since the dialog box will remain in the foreground for a few seconds while the calculation is in progress.

This is the code:

new AlertDialog.Builder(this) .setMessage("This may take a while") .setPositiveButton("OK", new android.content.DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // hide the OK button - how? // a lot of computation } }) .show(); 

How can i achieve this?

PS: I'm not interested in more complex methods of processing calculations (such as: progress dialogs, multithreading).

Thank.

+8
android alertdialog
Nov 27 2018-10-12T00:
source share
3 answers
 .setPositiveButton("OK", new android.content.DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { ((AlertDialog)dialog).getButton(which).setVisibility(View.INVISIBLE); // the rest of your stuff } }) 
+19
Nov 27 '10 at 10:51 on
source share
 setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.dismiss(); 

where dialog is DialogInterface .

0
Apr 10 '17 at 8:11
source share

You can set the button's visibility to invisible.

 ok.setVisibility(View.INVISIBLE); 
-3
Nov 27 '10 at 13:07
source share



All Articles