mvvmcrossmvxspinner

MVVMCross Spinner Showing Object Reference


Having issue while binding MvvmCross.Binding.Droid.Views.MvxSpinner with data.

Spinner dropdown showing perfectly fine with string but spinner title showing object reference only.

Spinner

<MvvmCross.Binding.Droid.Views.MvxSpinner
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                local:MvxDropDownItemTemplate="@layout/spinner_item"
                android:layout_marginLeft="5dp"
                android:dropDownWidth="257dp"
                android:dropDownSelector="@drawable/list_item_selector"
                local:MvxBind="ItemsSource Cities" />

Templete

<?xml version="1.0" encoding="utf-8"?>
<MvvmCross.Binding.Droid.Views.MvxLinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:local="http://schemas.android.com/apk/res-auto"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="#fafafa"
    android:orientation="horizontal">
    <TextView
        android:layout_width="match_parent"
        android:layout_height="32dp"
        android:textSize="15sp"
        android:textColor="#de000000"
        android:lineSpacingExtra="5sp"
        android:text="Shortness of breath"
        android:layout_marginTop="6dp"
        android:layout_marginBottom="6dp"
        android:layout_marginLeft="24dp"
        local:MvxBind="Text Name; Typeface StringToFont('Effra_Rg')" />
</MvvmCross.Binding.Droid.Views.MvxLinearLayout>

Please go through the link for snapshot


Solution

  • You are not providing a MvxDropDownItemTemplate:

    local:MvxDropDownItemTemplate="@layout/template"
    

    nor a MvxItemTemplate:

    local:MvxItemTemplate="@layout/template"
    

    The difference between these two are, that the Drop Down Item Template is what is show when the spinner is expanded. While the Item Template will be the first item shown when it is collapsed. You probably need to provide them both if you do not wish to use the default templates which just call ToString() on the ViewModel bound to the item.