Xamarin:在 mvvmcross 中使用片段
Xamarin: Using fragment in mvvmcross
我正在尝试在 MVVMCross Xamarin Adroid 应用程序中使用 ActionBar。我能够在片段中加载布局很好的问题是上下文总是指向 MainView 而不是布局视图。我试图更改上下文,但获取资源异常。错误是
Java.Lang.NullPointerException: 尝试在空对象引用
上调用虚拟方法'android.content.res.Resources android.content.Context.getResources()'
代码片段
public class LocationFragment : 片段
{
public 覆盖 View OnCreateView(LayoutInflater inflater,ViewGroup 容器,Bundle savedInstanceState)
{
//View view = inflater.Inflate(Resource.Layout.Location, null);
View view = inflater.CloneInContext(new LocationView().BaseContext).Inflate(Resource.Layout.Location, null);
return view;
}
}
其中一位 Android 本机开发人员告诉我,我无法更改上下文,因为视图总是从 MainActivity 驱动。如果那是对的,我该如何在我的视图中使用它?
ActionBar 已弃用。您可能应该使用工具栏,MvvmCross 提供了包含片段支持的示例:https://github.com/MvvmCross/MvvmCross-AndroidSupport/tree/master/Samples
我正在尝试在 MVVMCross Xamarin Adroid 应用程序中使用 ActionBar。我能够在片段中加载布局很好的问题是上下文总是指向 MainView 而不是布局视图。我试图更改上下文,但获取资源异常。错误是
Java.Lang.NullPointerException: 尝试在空对象引用
上调用虚拟方法'android.content.res.Resources android.content.Context.getResources()'代码片段
public class LocationFragment : 片段 { public 覆盖 View OnCreateView(LayoutInflater inflater,ViewGroup 容器,Bundle savedInstanceState) {
//View view = inflater.Inflate(Resource.Layout.Location, null);
View view = inflater.CloneInContext(new LocationView().BaseContext).Inflate(Resource.Layout.Location, null);
return view;
}
}
其中一位 Android 本机开发人员告诉我,我无法更改上下文,因为视图总是从 MainActivity 驱动。如果那是对的,我该如何在我的视图中使用它?
ActionBar 已弃用。您可能应该使用工具栏,MvvmCross 提供了包含片段支持的示例:https://github.com/MvvmCross/MvvmCross-AndroidSupport/tree/master/Samples