我正在尝试在DialogFragment中实现ProgressDialog并将其用作片段。我的onCreateDialog看起来像这样:
public Dialog onCreateDialog(Bundle savedInstanceState) {
String message = getArguments().getString("msg");
ProgressDialog dialog = new ProgressDialog(getActivity());
dialog.setMessage(message);
dialog.setTitle("");
dialog.setCancelable(true);
dialog.setIndeterminate(true);
dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
return dialog;
}
根据android开发人员的说法,要将此对话框用作Fragment,我必须实现onCreateView,它返回视图对象。问题是,我如何获得这种对话的视图?
答案 0 :(得分:2)
它只适用于onCreateDialog。 如果要创建更复杂的视图和片段,则应创建一个方法,例如:
public View onCreateView( . .. ) {
LayoutInflater inflater = getActivity().getLayoutInflater();
View view = inflater.inflate(R.layout.fragment_xml_id, null);
return view;
}
有关详情,请参阅此博客: http://android-developers.blogspot.com/2012/05/using-dialogfragments.html