Search code examples
androidxamarinmvvmcross

Multi-select list in MVVMCross using MvxSpinner


I have an OvservableCollection in the core, that I want to bind to my Android views. This works fine for single-selects, but I'm not so sure about how to bind a multi-select list.

MvxSpinner

<Mvx.MvxSpinner
     android:layout_width="fill_parent"
     android:layout_height="warp_content"
     android:id="@+id/spMultiList"
     local:MvxDropDownItemTemplate="@layout/itemspinner"
     local:MvxBind="ItemsSource source; SelectedItem SelectedItem" />

layout/itemspinner.xaml

 <?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-auto"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content">

     <TextView 
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_weight=".9"
      local:MvxBind="Text Description" />

      <CheckBox
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_weight=".1"
      android:checked="false"/>
 </LinearLayout>

Solution

  • In case anyone was wondering, this was resolved by added a 'Selected' boolean to the ItemList that the MvxSpinner binds to.

    itemspinner.xaml template can then be bound to this variable as follows:

    <CheckBox
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        local:MvxBind="Checked Selected"/>
    

    Now saves multiple checks.