0

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?

Klaus Nji
  • 18,107
  • 29
  • 105
  • 185

1 Answers1

1

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

fmaccaroni
  • 3,846
  • 1
  • 20
  • 35
  • Turned out to be the namespace. Made change as suggested and this cleared it up. However, I am now getting these warnings: The 'http://schemas.android.com/apk/res-auto:MvxBind' attribute is not declared – Klaus Nji May 31 '18 at 18:00
  • As it states here https://github.com/MvvmCross/MvvmCross/issues/1413 you can ignore that warning – fmaccaroni May 31 '18 at 18:50
  • @KlausNji If it worked, please accept the answer, if not let me know to see if I can help – fmaccaroni Jun 05 '18 at 15:46