This is a tutorial about simple spinner which allows to select an item from a drop down menu. I am displaying static data in spinner and after selecting an item from spinner a toast message will be shown.

Download Code

Creating new Project

1. Create a new project and fill the required details File ⇒ New ⇒ Android Project
2. Open strings.xml file under resources folder and add following items. Add Spinner dialog tile in string resources.

<?xml version="1.0" encoding="utf-8"?>
    <string name="app_name">AndroidSpinnerExample</string>
    <string name="spinner_title">Select Category</string>

3. Now open your main.xml and design a simple layout with text label and a spinner.

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

    <!-- Text Label -->

    <!-- Spinner Element -->

4. Open your main activity and extend it from OnItemSelectedListener

public class AndroidSpinnerExampleActivity extends Activity implements OnItemSelectedListener{

5. After extending your activity from OnItemSelectedListener write the following code. In the following code i am creating a simple list with list of item needed to show in spinner. And finally i am attaching those items to spinner.

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

public 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&lt;String&gt; categories = new ArrayList&lt;String&gt;();
        categories.add("Business Services");

        // Creating adapter for spinner
		ArrayAdapter&lt;String&gt; dataAdapter = new ArrayAdapter&lt;String&gt;(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&lt;?&gt; 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&lt;?&gt; arg0) {
		// TODO Auto-generated method stub



6. Run your project.


android spinner dropdown
This image is for thumbnail purpose
android spinner dropdown
Hi there! I am Founder at androidhive and programming enthusiast. My skills includes Android, iOS, PHP, Ruby on Rails and lot more. If you have any idea that you would want me to develop? Let’s talk:
  • Jhonny Makis

    Thanks Ravi!! Very useful!!
    Muito Obrigado, o seu site está me ajudando bastante!

  • mangesh kaduskar

    Spinner spinme=(Spinner)findViewById(;

    final MyData spin1[] = new MyData[5];

    spin1[0] = new MyData( “Hello”,”World” );

    spin1[1] = new MyData( “Android”,”Here” );

    ArrayAdapter adapter =new ArrayAdapter(this,android.R.layout.simple_spinner_item,spin1);

    spinme.setOnItemSelectedListener(new OnItemSelectedListener() {


    public void onItemSelected(AdapterView arg0, View arg1,int arg2, long arg3) {

    // TODO Auto-generated method stub

    int a= spin1[arg2];

    String b = arg0.getItemAtPosition(arg2).toString();



    public void onNothingSelected(AdapterView arg0) {

    // TODO Auto-generated method stub



  • alfian

    hi ravi, such a nice tutorial. i have tried your code, but it can’t show prompt message like in the picture. how can i show prompt for spinner?

  • Navdeep Agrawal

    Hay Ravi why are you change design of our page?
    I think previous view was better than current view because readable content should be center in page.

  • yoominho

    thank you

  • Gokul

    how to set background color to dropdown items in android …………..rply it

  • george

    Hi all. I am a novice in developing app and thanks to
    Ravi for all good work that is doing . I’m working at a simple app and I get
    stuck . if you have knowledge of
    building android apps, and make team
    with me please replay to . Thanks ang
    good luck for all your projects..

    • kapil goyal

      hi all…

      i am also a novice in app developement.. thanks ravi

  • Name


  • hellboy

    one of the best site
    u hav all d resourses

  • divya

    can anyone guide to view the output in android phone instead of emulator
    i have installed adb driver but i cant able to see my device in devices

  • anwar sathath mohamed jaffarul

    good material, it is working fine

  • Guest

    hi Ravi its not working fine give error at

    List<String> categories = new ArrayList<String>();


    categories.add(“Business Services”);

    ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, categories);



  • Somnath

    Hello Ravi,
    Nice Tutorial, However, when we select the same item from the spinner. It does not call the OnItemSelected Method. Any workarounds?

    • Sumanta B

      you have use this line spinner.setOnItemSelectedListener(this);

  • Rana Saqib Manj

    how to add design in spinner not a list ….. how is it possible ??

  • Bernadeth Cacao

    Hello Mr.Rav Tamada. Why I can’t received any email verification on my email. I really wanted to try your tutorial. But I can’t subscribe in this site. Please help me. Thanks. 🙂

  • Pramod HN

    sir, how to access the image button through spinner,, example: when ever we click on particular city on spinner.. the related areas to that city should displayed in image button,,, that is each area should be displayed in individual image button…

  • hackerkernel
  • dhara

    It Doesn’t display Radio Buttton

    • tarun sharma

      hi Dhara

      did you get any solution for this beacause m having the same problem.

  • tarun sharma

    Hi Ravi,

    I coded the this one but it is not displaying the Radio Button.

  • Mario German Agudelo

    Thank you very much for sharing your knowledge with everyone, could you help me I need to place a spinner in a recyclerview, you have some tutorial or link in which to do this process, I appreciate all your help.

  • panchami Mohan

    Hi, is it possible to select multiple items in spinner? Thank you

  • Divya Munjal

    can anyone tell me how to select multiple values from spinner?

    • Abhishek Malviya

      Spinner is mutually exclusive u can select only one item at a time

  • Shubham Sharma

    country ,state and district k liye spinner kese banayenge JSON use kerke volley k saath.agar country per click kere to india select ho and state me india k states aaaye.
    please tell me.

  • Talal AboCarlos Oman

    thank you sir
    and i hope to see three spinner like customer location
    country, state, city
    use php & mysql

  • Farrukh Saleem

    when i run this code then lot of errors in it.
    i am using android studio.
    see errors in image file

    • Dilshad Khan

      Bro @Farrukh you are using code in Android Studio and basically this tutorial is so old that’s way you got some error in this code so try this code

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

      // Spinner click listener

      // Spinner Drop down elements
      List categories = new ArrayList();
      categories.add(“Business Services”);

      // Creating adapter for spinner
      ArrayAdapter dataAdapter = new ArrayAdapter (getActivity(), android.R.layout.simple_spinner_item, categories);

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

      // attaching data adapter to spinner

      • Farrukh Saleem

        thanks bro

  • Ray Vaniya

    how to achieve same functionality using data binding, can you please provide full functional example with code

  • Anoop Varghese

    How to display large string when an item in select catagory is selected?Suppose if someone selects automobile i need to show some description about automobile as text.Like that for education another text.

  • hasim shaikh

    i am getting this error:
    Attempt to invoke virtual method ‘void android.widget.Spinner.setOnItemSelectedListener(android.widget.AdapterView$OnItemSelectedListener)’ on a null object reference

    i have implemented OnItemSelectedListener also

  • Niyanta
  • Padmaja Rani Bodsakurthi

    can u please post the searchable spinner source code

  • Malini

    Hi ravi,
    How to post edit text and spinner data(get spinner data from service)to server.I need both get and post in same file.
    Thanks in advance.

    • Could you explain your questions a bit?

      • Malini

        I want to post simple form data to server using all controls like edittext,spinner and image etc.for that i need to get spinner’s data and bind to form

  • wenjuan

    i used simple_spinner_dropdown_item layout, but did not get same nice drop down view as you.