【问题标题】:How to disable/enable progress dialog button如何禁用/启用进度对话框按钮
【发布时间】:2012-12-11 22:00:52
【问题描述】:

我想显示一个进度对话框,它只会在需要时显示“关闭”按钮,例如当进度值达到其最大值时。在那个“关闭”按钮上,我想关闭对话框。我用否定按钮制作了进度对话框,当用户单击它时我可以将其关闭,但我不希望“关闭”按钮在我想要或进度完成时一直可见/启用。

谢谢。

【问题讨论】:

  • 我认为使用 Asynctask 是可能的
  • @Guillaume 我正在使用 asyncTask,以前我在 postexecute 上关闭对话框,但现在我想将最终状态显示为对话框文本,并让用户选择关闭它。如何禁用关闭按钮然后启用它?
  • 你可以使用 setVisible(android.View.VISIBLE)setVisible(android.View.INVISIBLE) developer.android.com/reference/android/view/…

标签: android progressdialog


【解决方案1】:

要基于 Guillaume 的评论和 Karim 的回答,您可以像这样隐藏/显示或启用/禁用 ProgressDialog 上的按钮:

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);

您可以挂在Button 上,以便稍后在您的任务完成后启用。请务必在拨打show 后拨打getButton

【讨论】:

    【解决方案2】:

    您应该使用 ProgressBar 和 Button 构建自定义对话框。然后使用 Button.setVisibility(View.VISIBLE) 和 Button.setVisibility(View.INVISIBLE)

    【讨论】:

      猜你喜欢
      • 2012-01-04
      • 1970-01-01
      • 1970-01-01
      • 2014-11-25
      • 2020-07-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-08
      相关资源
      最近更新 更多