We are going to learn and find about Spinner in Android and let’s start by understanding what a Spinner is.
A Spinner is a type of view or object that holds items in the form of a dropdown menu in android app which are available for user selection and which creates a menu with multiple options so that a user can select any one option. Following is an example of a spinner.
We can create a Spinner, by adding the following code to our layout XML file:
What’s the difference between Spinner and ListView?
Both ListView and Spinner view looks very similar. But they differ from each other.
Spinners provide a quick way for selecting only one value from a provided set of values and in the default state, a spinner can only shows the currently selected one value and Whenever you touch(tap on) the spinner, it will shows a dropdown menu with all other available options(values) in the from which the user can select a new one.
ListView on the other hand, is a view group that store multiple data in a list of scrollable items and The list items are automatically inserted to the list using an Adapter that pulls content from a data source(DS) such as an database table or array and converts each dataitem into a view that is placed in the list.
Therefore, a Spinner view and ListView differs in the way they appear and in their usage too. If we want to select only one value from a set of options then you should use a Spinner so, if you want to display a list of data then use a list view.