【发布时间】:2014-03-14 13:22:17
【问题描述】:
我有这个带有按钮的 Android 活动/布局。当我单击此按钮时,它会打开一个带有 2 个微调器的 DialogFragment。当 DialogFragment 出现时,我需要使用 Web 服务返回的项目填充这 2 个微调器。因此,在等待服务返回时,我想在刚刚打开的 DialogFragment 上显示一个 ProgressDialog。
问题是我似乎无法在 DialogFragment 之上创建 ProgressDialog。我可以看到 ProgressDialog 显示在 DialogFragment 后面,是否可以让 ProgressDialog 显示在其他所有内容之上?
我的代码是这样的:
public class RegionalFragment extends DialogFragment {
private View view;
private Activity activity;
private Spinner spinner1;
private Spinner spinner2;
private ProgressDialog progressDialog;
public RegionalFragment(Activity activity) {
this.activity = activity;
LayoutInflater inflater = activity.getLayoutInflater();
view = inflater.inflate(R.layout.spinner_selection, null);
this.progressDialog = new ProgressDialog(activity);
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder =
new AlertDialog.Builder(activity)
.setTitle(R.string.title)
.setView(view)
.setPositiveButton(R.string.ok, new MyListener(activity))
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
getDialog().cancel();
}
});
progressDialog.getWindow().setBackgroundDrawable(new ColorDrawable(1));
progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progressDialog.setCancelable(false);
progressDialog.setIndeterminate(true);
progressDialog.setMessage("Please wait...");
progressDialog.show();
invokeAsyncWebService();
return builder.create();
}
谢谢!
【问题讨论】:
标签: android progressdialog android-dialogfragment