Klaus Nji
Klaus Nji

Reputation: 18857

MvxSpinner binding to ItemSource property not working

I have a very simple snippet as follows:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:local="http://schemas.android.com/apk/lib/com.myco.app"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="20px">
    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textSize="24dp"
        android:layout_marginTop="10dip"
        android:text="@string/planATripLabel"
        android:textColor="#FF9900" />
    <Spinner
        android:id="@+id/spinner"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:prompt="@string/planet_prompt" />

  <!--local:MvxBind="ItemsSource Items; " />-->

    <MvxSpinner
        android:id="@+id/spinner1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:prompt="@string/planet_prompt"
        local:MvxBind="ItemsSource Items" />
</LinearLayout>

The ViewModel contains the following code:

 private ObservableCollection<string> _items = new ObservableCollection<string>()
        {
            "One", "Two", "Three"
        };
        public ObservableCollection<string> Items
        {
            get
            {
                return _items;
            }
            set { _items = value; RaisePropertyChanged(() => Items); }
        }

However, when I run the application nothing is displayed. The regular spinner does show its items as I have code in the view class itself copied from Xamarin's site like so:

  Spinner spinner = FindViewById<Spinner>(Resource.Id.spinner);

            spinner.ItemSelected += new EventHandler<AdapterView.ItemSelectedEventArgs>(spinner_ItemSelected);
            var adapter = ArrayAdapter.CreateFromResource(
                this, Resource.Array.planets_array, Android.Resource.Layout.SimpleSpinnerItem);

            adapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);
            spinner.Adapter = adapter;

What am I missing?

Upvotes: 0

Views: 223

Answers (1)

fmaccaroni
fmaccaroni

Reputation: 3916

I think your local namespace is not taking into account MvxBind.

I'd replace

xmlns:local="http://schemas.android.com/apk/lib/com.myco.app"

with (I always use it like this, with res-auto)

xmlns:local="http://schemas.android.com/apk/res-auto"

And if that's not the problem I'd provide a custom MvxItemTemplate and a custom MvxDropDownItemTemplate to the MvxSpinner to see if the defaults are not working. And also check the Outputwindow to see if any errors are being displayed.

If you need any help with that just tell me.

HIH

Upvotes: 1

Related Questions