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

六眼飞鱼酱① 提交于 2019-12-20 10:57:53

问题


I have been developing an Android app.

I would like to hide the OK button after the user presses it, as the dialog window will stay at the foreground for some seconds while a computation takes place.

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 that?

P.S.: I am not interesting to more advanced techniques to handle a computation (such as: progress dialogs, multi-threading).

Thanks.


回答1:


.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
    }
})



回答2:


setPositiveButton("Ok", new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int id) {
        dialog.dismiss();

where dialog is DialogInterface.




回答3:


You can set the visibility of button to invisible.

ok.setVisibility(View.INVISIBLE);


来源:https://stackoverflow.com/questions/4291548/android-alert-dialog-how-to-hide-the-ok-button-after-it-being-pressed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!