Android Spinner data binding

from the CommonsWare Community archives

At March 25, 2020, 6:46am, dcc88508332 asked:

Is there a way to data-binding current select value of spinner then pass it to button click method.

<layout ... >

            type="..." />

        ... >

            app:onItemSelected="@={viewModel.typePosition}" // two-way binding spinner current select value 
            ... />

            android:onClick="@{() -> viewModel.addType(userAddType.currentValue)}" // get the current value of spinner and pass it to button method
            ... />


At March 25, 2020, 11:52am, mmurphy replied:

I have not used Spinner in ~4 years. I do not like two-way data binding, so other than my few book examples showing it, I have skipped it. As a result, I do not have a recipe for two-way data binding of a Spinner.