Bind to spinners selecteditem

19 Views Asked by At

Is it possible to bind to a spinners selected item directly in the layout file?

I know I can bind a TextViews' text property directly to an EditText text property like this:

<EditText
    android:id="@+id/some_input"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="text"/>

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text='@{someInput.text}'/>

But what I really want is to display the selected item of a spinner in the textview. Something like this:

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text='@{mySpinner.selectedItem.toString()}'/>

This gives me a binding error: "Could not resolve the two-way binding attribute \u0027selectedItem\u0027 on type \u0027android.widget.Spinner\u0027"

What does it mean and how can I solve this?

0

There are 0 best solutions below