我正在尝试使用自己的布局创建DialogFragment。
我看到了几种不同的方法。有时在OnCreateDialog中设置布局,像这样: (我正在使用Mono,但我已经习惯了Java)
public override Android.App.Dialog OnCreateDialog (Bundle savedInstanceState)
{
base.OnCreateDialog(savedInstanceState);
AlertDialog.Builder b = new AlertDialog.Builder(Activity);
//blah blah blah
LayoutInflater i = Activity.LayoutInflater;
b.SetView(i.Inflate(Resource.Layout.frag_SelectCase, null));
return b.Create();
}
这个第一种方法对我来说很有效...直到我想使用 findViewByID
。
所以,在经过一番搜索后,我尝试了第二种方法,它涉及覆盖 OnCreateView
因此,我注释了两行设置布局的 OnCreateDialog
代码,并添加了以下内容:
public override Android.Views.View OnCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View v = inflater.Inflate(Resource.Layout.frag_SelectCase, container, false);
//should be able to use FindViewByID here...
return v;
}
这给了我一个可爱的错误:
11-05 22:00:05.381: E/AndroidRuntime(342): FATAL EXCEPTION: main
11-05 22:00:05.381: E/AndroidRuntime(342): android.util.AndroidRuntimeException: requestFeature() must be called before adding content
我被难住了。