

Lastly, it also supports emptyText XML attribute which is used as default text if there are no items in the adapter. If the selectedPosition is programmatically updated, the component automatically notifies listeners and updates the selected text. Later we will also create a custom adapter which automatically gets notified when the selection changes. This component automatically tracks the position of the currently selected item by monitoring user clicks and notifies registered listeners. Step 1 'strings. It displays the currently selected value and touching the spinner gives a drop-down list from which we can choose the required value. It provides a quick way to select a value from a list. A Spinner is similar to a drop-down list. Material Spinnerįirst, let’s create our new custom UI component called MaterialSpinner which extends AutoCompleteTextView. This article explains how to create a Spinner in Android. However, I have implemented the Spinner in a different, reusable way using custom binding adapters, two-way data binding and selection tracking. It also shows some details about manually styling the component. I’ve learned about these components from this excellent article and I give the author credit for the research. I think it is really weird the only official way for implementing a Spinner with Material theme is abusing a component whose original purpose is completely different. If you check the Material design website, it mentions something called “ Exposed dropdown menu” which uses the TextInputLayout and AutoCompleteTextView, making everything even more confusing.

Switches are shown below the Spinner and are not its part, but it is difficult to distinguish.
