1

我试图在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开发者,使用此对话框作为一个片段,我必须实现onCreateView,它返回视图对象。问题是,我怎样才能看到这样的对话框?

回答

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