Android的警告对话框 - 如何隐藏确定按钮它是pressed后它是、对话框、按钮、Android

2023-09-05 01:05:16 作者:17.清厮酿

我一直在开发一个Android应用程序。

我想隐藏确定按钮,用户presses后,为对话窗口会留在前台几秒钟而​​计算的发生。

这是在code:

 新AlertDialog.Builder(本)
    .setMessage(这可能需要一段时间)
    .setPositiveButton(OK,新android.content.DialogInterface.OnClickListener(){
        @覆盖
        公共无效的onClick(DialogInterface对话,诠释它){
                       //隐藏确定按钮 - 怎么样?
                       //大量的运算
        }
    })
    。显示();
 

我怎样才能做到这一点?

PS:我不是有趣的更先进的技术来处理计算(如:进程对话,多线程)。

感谢。

解决方案

  .setPositiveButton(OK,新android.content.DialogInterface.OnClickListener(){
    @覆盖
    公共无效的onClick(DialogInterface对话,诠释它){
         ((AlertDialog)对话框).getButton(所).setVisibility(View.INVISIBLE);
         //你的东西休息
    }
})
 
Android安卓编程入门 按钮弹出对话框

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.

解决方案

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

 
精彩推荐