

The third layout argument passed to the constructor call is basically how the spinner control will look like when a manual selection is made (or the default one is showing up). The createFromResource method allows us to create an ArrayAdapter from the string array resource. specify the layout to use when the list of choices appearsĪtDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) R.anets_array, android.R.layout.simple_spinner_item) create an ArrayAdapter using the string array and a default spinner layoutĪrrayAdapter adapter = ArrayAdapter.createFromResource(this, You can also load a spinner using an adapter for a dynamic source of options using an Adapter: Specify the string array of options in res/values/planets_array.xml

ArrayAdapter and CursorAdapter (or SimpleCursorAdapter) are indirect sub classes of SpinnerAdapter. The data used to populate the Spinner can come from various sources but must be provided through a SpinnerAdapter like an ArrayAdapter if the source is an array or a CursorAdapter for result sets from database queries. String value = spinner.getSelectedItem().toString() Spinner spinner = (Spinner) findViewById(R.id.spinner) Get the selected item out a spinner using: It references to an array resource that will populate the Spinner.Ĭreate a spinner like any view and specify the android:entries attribute to specify the set of options: Dialog mode uses a dialog window for selecting spinner options and DropDown mode uses drop-down anchored to the Spinner for selecting spinner options. This property has two options: Dialog mode and DropDown mode. It defines display mode for spinner options. The prompt to display when the spinner’s dialog is shown. Some important properties of spinner are:


Spinner provides a quick way to select one value from a set of options (like select dropdowns in HTML).
