我正在尝试使用自己的布局创建一个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();
}
Run Code Online (Sandbox Code Playgroud)
第一种方法对我有用......直到我想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;
}
Run Code Online (Sandbox Code Playgroud)
这给了我一个可爱的错误:
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
Run Code Online (Sandbox Code Playgroud)
我很难过.