我正在使用Xamarin和MVVMCross开发Android应用程序。
当尝试填充旨在为用户提供选择列表的布局时,我遇到了以下异常。 该怎么解决或绕过这个问题?
异常:
Cirrious.CrossCore.Exceptions.MvxException:在创建MvxAdapter期间绑定上下文为空 - 仅当已将特定绑定上下文放置在堆栈上时才应创建适配器
来源:
var alertBuilder = new AlertDialog.Builder(this);
var view = LayoutInflater.Inflate (Resource.Layout.HeadPartSelectionView, null);
布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res/xxxxxxxxx.xxx.Android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/redpink"
android:id="@+id/layoutCancelNextButtons">
<Button
android:text="Cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/buttonCancelHeadPart"
android:layout_weight="1"
android:textColor="@color/white"
android:background="@color/redpink" />
<Button
android:text="Next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/buttonCancelHeadPart"
android:id="@+id/buttonSelectHeadPart"
android:layout_weight="1"
android:textColor="@color/white"
android:background="@color/redpink" />
</LinearLayout>
<Cirrious.MvvmCross.Binding.Droid.Views.MvxListView
android:layout_width="fill_parent"
android:layout_height="120dp"
android:id="@+id/listHeadPart"
android:layout_below="@id/layoutCancelNextButtons"
android:textColor="@color/darkgrey"
android:background="@color/white"
local:MvxBind="ItemsSource SubAreas"
local:MvxItemTemplate="@layout/list_headpicklist" />
</RelativeLayout>
ListView 布局文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res/xxxxxxxxx.xxx.Android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_gravity="center"
android:textColor="@color/darkgrey"
local:MvxBind="Text Name"
android:textSize="24dp" />
</LinearLayout>
base.EnsureBindingContext(Bundle)
已被移除。现在您可以使用MvxFragmentExtensions.EunsureBindingContextSet(IMvxFragmentView)
来实现相同的结果。 - Trevor Balcom