Spinner It is a type of dropdown input. Firstly in layout

    android:id="@+id/spinner"     <!-- id to refer this spinner from JAVA-->

Now Secondly populate values in spinner There are mainly two ways to populate values in spinner.

  1. From XML itself create a array.xml in values directory under res. Create this array
<string-array name="defaultValue">
    <item>--Select City Area--</item>
    <item>--Select City Area--</item>
    <item>--Select City Area--</item>

Now add this line in sppiner XML

  1. You can also add values via JAVA

if you are using in activity cityArea = (Spinner) findViewById(R.id.cityArea); else if you are using in fragment

cityArea = (Spinner) findViewById(R.id.cityArea);

Now create a arrayList of Strings

ArrayList<String> area = new ArrayList<>();
//add values in area arrayList
cityArea.setAdapter(new ArrayAdapter<String>(context
                            , android.R.layout.simple_list_item_1, area));

This will look like



According to the device Android version it will render style

Following are some of the default themes

If an app does not explicitly request a theme in its manifest, Android System will determine the default theme based on the app’s targetSdkVersion to maintain the app’s original expectations:


Spinner can be easily customized with the help of xml eg