Android Spinner Tutorial - Spinner Style and Example | W3schools

Spinner is an Android User Interface (UI) control which lets a user select an option from the drop-down list.

Also Read: Android RadioButton Control

In the above screenshot of Gmail application, you can easily see a drop-down menu with three options, which are Reply, Reply All, and Forward. The Spinner UI control makes it possible for the user to select any one of the provided options from a drop-down list.
In the below example, we will be explaining a step-to-step guide on how to use this Spinner control in your Android application. In this application, you will be displaying a drop-down menu to the user which will be carrying a list of categories.

Step 1: Let’s start with the creation of an Android application on the Android Studio IDE. Save this application as AndroidSpinnerExample. Make sure you store this application under the com.example.spinner package.


Step 2: You need to update the file. You can easily locate this file under the src/com.example.spinner directory. Here, you will be creating a list view for the items to be displayed on the Spinner.

package com.example.spinner;
import java.util.ArrayList;
import java.util.List;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Toast;
import android.widget.AdapterView.OnItemSelectedListener; 

class AndroidSpinnerExampleActivity extends Activity implements OnItemSelectedListener
   public void onCreate(Bundle savedInstanceState)

      // Spinner element
      Spinner spinner = (Spinner) findViewById(;      

      // Spinner click listener

      // Spinner Drop down elements
      List<String> categories = new ArrayList<String>();

      categories.add(“Business Services”);

      // Creating adapter for spinner
      ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, categories);      

      // Drop down layout style – list view with radio button

      // attaching data adapter to spinner

   public void onItemSelected(AdapterView<?> parent, View view, int position, long id)
      // On selecting a spinner item
      String item = parent.getItemAtPosition(position).toString();      

      // Showing selected spinner item
      Toast.makeText(parent.getContext(), “Selected: ” + item, Toast.LENGTH_LONG).show();

   public void onNothingSelected(AdapterView<?> arg0)
      // TODO Auto-generated method stub


Step 3: Add the below provided XML code to the main_activity.xml file. Trace the res/layout/ path to locate this file.

<?xml version=”1.0″ encoding=”utf-8″?>
<LinearLayout xmlns:android=””



Step 4: Android Studio will take care of the definitions of the new string constants. This section of the application will automatically occur in the strings.xml file. You can find this file under the res/values/ directory. 

<?xml version=”1.0″ encoding=”utf-8″?>
   <string name=”app_name”>AndroidSpinnerExample</string>


Step 5: The already existing content of the AndroidManifest.xml file is shown below.

<?xml version=”1.0″ encoding=”utf-8″?>
<manifest xmlns:android=””
   package=”com.example.spinner” > 
      android:theme=”@style/AppTheme” >      

      <activity       android:name=”com.example.spinner.AndroidSpinnerExampleActivity”
         android:label=”@string/app_name” >     
            <action android:name=”android.intent.action.MAIN” />
            <category android:name=”android.intent.category.LAUNCHER” />

Step 6: Now, you need to run the AndroidSpinnerExample application on the Android Studio IDE. Before we proceed any further, we are assuming that you have already created your AVD during the environment setup. Open one of the activity files of your project and Run the application. The successful completion of the process will display the final output on the Emulator window.

Once you click on the Automobile spinner button, it will appear as a drop-down menu displaying various categories on the screen.