是否可以将AlertDialog内容更改为ProgressBar?

问题描述:

DialogFragment其中onCreate我创建一个简单的AlertDialog是否可以将AlertDialog内容更改为ProgressBar?

AlertDialog alertDialog = new AlertDialog.Builder(getContext()) 
      .setTitle(R.string.dialog_title) 
      .setMessage(R.string.dialog_message) 
      .setPositiveButton(R.string.positive_button, new DialogInterface.OnClickListener() { 
       @Override 
       public void onClick(DialogInterface dialogInterface, int i) { 


       } 
      }) 
      .create(); 

如你我没有使用任何自定义布局,因为我只需要一个简单的对话框中看到。 在onClick我想拨打网络服务并将对话内容更改为ProgressBar。有没有可能做到这一点,而不使用自定义布局?用编程方式用ProgressBar夸大视图并将其设置为对话框?

+0

有进度条上没有任何按键,所以如果你不想定制任何布局,您必须隐藏警报并显示进度条onClick事件 – guisantogui

+1

您无法将'View'添加到默认布局。你只能膨胀一个视图,或者你可以用编程方式创建一个可以添加到对话框的布局,最后基本上与从xml膨胀的对话框相同。 – Pztar

使用进度对话框,更简单

ProgressDialog progressDialog = new ProgressDialog(context); 
progressDialog.setTitle("Please wait"); 
alertDialog.dismiss(); 
progressDialog.show(); 

使用ProgressDialouge为您的工作。

一个简单的用法是

ProgressDialog progressdialog = new ProgressDialog(getApplicationContext); 
progressdialog.setMessage("Processing..."); 
progressdialog.show(); 

当你的工作完成呼叫

progressdialog.dismiss();`