Android Spinner (Drop Down)


In general Android Spinner are famous by the name Drop-down. Android Spinner provides a way to enlist multiple items and allow user to select one item out of them. Apart from normal UI Android Spinners can be customised in several ways which will also be covered in this tutorial.



DownloadSource Code :


Now Let us work on Project : (Refer – Configuring Existing AndroidStudioProject) Spinner which you might have downloaded from above or you can follow the scripts below by copying it to implement in your Project. To launch Downloaded project, Extract the zip, copy it into AndroidStudioProjects. Now from Android Studio click open Existing Android Studio Project and select the path to extracted file we just copied in AndroidStudioProjects directory. If Sync SDK path prompt comes just click OK and you are ready to work. If still you get error check for AndroidStudioProjects/Spinner/app/build.gradle , it will contain different SDK Version. Change it to SDK Version which you have.



1. activity_main.xml : Layout file

<RelativeLayout xmlns:android=""
    tools:context=".MainActivity" >

        android:layout_alignParentTop="true" />

  •  We have simply added a spinner inside Relative Layout.




package com.nestedif.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;

public class MainActivity extends Activity {
	private Spinner spinner_OS;

	protected void onCreate(Bundle savedInstanceState) {
		spinner_OS = (Spinner) findViewById(;
		//	We add items for Spinner using below ArrayList
		ArrayList<String> OS_list = new ArrayList<String>();
		 You can replace these one-by-one to change Visual UI for our Spinner with Line-56 		
		//ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, OS_list);
		//ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_activated_1, OS_list);
		//ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_checked, OS_list);
		//ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_multiple_choice, OS_list);
		//ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_single_choice, OS_list);

		//	Array Adapter connects our List-Data(OS_list) with our Spinner 
		ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, OS_list);

		//	Item Select Listener for Spinner 
		spinner_OS.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() 
			//	This method is called when we select any item from our Spinner 
		    public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) 
		        Toast.makeText(getApplicationContext(), spinner_OS.getSelectedItem().toString() , Toast.LENGTH_LONG).show() ; 
			//	This method is called when no item is selected from our Spinner
		    public void onNothingSelected(AdapterView<?> parent) 



Explaining above Code :

  • Line 16 & 23 We have declared spinner and linked it with that of (activity_main.xml) Layout file.
  • Line 27 We make a ArrayList which will hold all the option-items for our Spinner.
  • Line 28-35 Next we add items on-by-one to this arrayList. (While using this arraylist with DB you will just have to repeat this process inside loop). Remember that over here we are just populating arrayList, our spinner is still empty.
  • Line 56  ArrayAdapter are used to add values from our ArrayList to Spinners and to customize our Spinner. You will see 3 parameters for ArrayList on right side. 1st parameter is context, 2nd is to customize look of our spinner & 3rd is data source i.e. our ArrayList. (You will see comment from Line 40-52 replace them one-by-one with this line to see various themes for spinner )
  • Line 57 We associate this arrayAdapter with our spinner declared. So now our spinner is populated with values.
  • Line 64-75 This block adds itemSelectListener to our spinner, inside this the method onItemSelected gives you the position and  value for selected item.



Final Output :

Android Spinner


Do It Yourself :

Try various custom views for the spinner using ArrayAdapter at Line-56 which using commented line-41-50



Report Errors + Bugs & Become Insider for

We would like to hear you, if you find any error or misspelled phrase while reading our tutorials. By reporting mistakes through email to you could help other peers.