Kla*_*Nji 5 itemtemplate android-layout mvvmcross xamarin itemtemplateselector
如果我有一个带有以下MvxListView定义的视图:
<Mvx.MvxListView
android:layout_marginTop="10px"
android:textFilterEnabled="true"
android:choiceMode="singleChoice"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textSize="20dp"
local:MvxBind="ItemsSource Data; ItemClick LaunchCapabilityViewCmd"
local:MvxItemTemplate="@layout/itemtemplate1" />
Run Code Online (Sandbox Code Playgroud)
而不是将MvxItemTemplate硬编码为itemtemplate1,可以根据我想在此视图中显示的数据类型动态设置它吗?我正在寻找与WPF的DateTemplateSelector类似的功能.
TIA.
您必须使用自定义适配器才能执行此操作.
一些样本显示了如何使用细胞类型选择.看到:
https://github.com/slodge/MvvmCross-Tutorials/tree/master/Working%20With%20Collections中的多态列表
https://github.com/slodge/MvvmCross-Tutorials/tree/master/Sample%20-%20CirriousConference中的会话列表视图中的分组列表
例如,来自PolymorphicListItemTypesView.cs
protected override View GetBindableView(View convertView, object source, int templateId)
{
if (source is Kitten)
templateId = Resource.Layout.ListItem_Kitten;
else if (source is Dog)
templateId = Resource.Layout.ListItem_Dog;
return base.GetBindableView(convertView, source, templateId);
}
Run Code Online (Sandbox Code Playgroud)
对于Android,还有一个优化应该添加到现有的多态适配器样本 - 包括使用GetItemViewType以便更好地convertView重用 - 请参阅https://github.com/slodge/MvvmCross/issues/333
这个问题与以下内容有关: