MvvmCross: selecting a dynamic element template for an 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" /> 

Instead of hard coding the MvxItemTemplate to itemtemplate1, is 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 for WPF DateTemplateSelector.

TIA.

+4
source share
1 answer

You must use a custom adapter for this.

A few examples show how to use cell type selection. Cm:

eg. from 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); } 

There is also an optimization for Android that needs to be added to existing polymorphic adapter samples - enable the use of GetItemViewType for better reuse of convertView - see https://github.com/slodge/MvvmCross/issues/333

These questions are related to:

+5
source

Source: https://habr.com/ru/post/1492002/


All Articles