MvvmCross:动态项模板选型MvxListView [英] MvvmCross : dynamic item template selection for MvxListView

查看:119
本文介绍了MvvmCross:动态项模板选型MvxListView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有以下MvxListView定义视图:

If I have a view with the following MvxListView definition:

<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" />

而不是硬编码MvxItemTemplate到itemtemplate1,它能够动态地设定这个基于我想在此视图中显示的数据的类型?我找了类似的功能WPF的DateTemplateSelector。

Instead of hard coding MvxItemTemplate to itemtemplate1, it it possible to dynamically set this based on the type of data I want to display in this view? I am looking for similar functionality to WPF's DateTemplateSelector.

TIA。

推荐答案

您必须使用自定义适配器来做到这一点。

You have to use a custom adapter to do this.

有几个样品展示了如何使用细胞类型的选择。参见:

A few of the samples show how to use cell type selection. See:

https://github.com/slodge/MvvmCross-Tutorials/tree/master/Sample%20-%20CirriousConference

例如。从<一个href=\"https://github.com/slodge/MvvmCross-Tutorials/blob/master/Working%20With%20Collections/Collections.Droid/Views/PolymorphicListItemTypesView.cs\"相对=nofollow> 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);
        }

对于Android,还有哪些应该被添加到现有的多态适配器样品进行优化 - 包括更好的 convertView <使用 GetItemViewType 的/ code>重用 - 见 https://github.com/slodge/MvvmCross/issues/ 333

For Android, there is also an optimisation which should be added to the existing polymorphic adapter samples - to include use of GetItemViewType for better convertView reuse - see https://github.com/slodge/MvvmCross/issues/333

此问题链接到:

  • Several item templates in one listbox in mvvmcross Android
  • getViewTypeCount and getItemViewType methods of ArrayAdapter

这篇关于MvvmCross:动态项模板选型MvxListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆