【发布时间】:2012-10-26 18:15:02
【问题描述】:
我正在尝试使用我自己的布局创建一个 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
我被难住了。
【问题讨论】:
-
为时已晚,但仍在发布类似内容:stackoverflow.com/questions/21258228/…
标签: java android mono xamarin.android android-inflate