Spinner in Android with Example Last Updated : 12 Jul, 2025 Comments Improve Suggest changes 17 Likes Like Report Android Spinner is a view similar to the dropdown list which is used to select one option from the list of options. It provides an easy way to select one item from the list of items and it shows a dropdown list of all values when we click on it. The default value of the android spinner will be the currently selected value and by using Adapter we can easily bind the items to the spinner objects. Generally, we populate our Spinner control with a list of items by using an ArrayAdapter in our Kotlin/Java file. Important Attributes for Spinner WidgetXML attributesDescriptionandroid:idUsed to specify the id of the view.android:textAlignmentUsed to the text alignment in the dropdown list.android:backgroundUsed to set the background of the view.android:paddingUsed to set the padding of the view.android:visibilityUsed to set the visibility of the view.android:gravityUsed to specify the gravity of the view like center, top, bottom, etcSteps to Implement SpinnerHere is an example of an Android application that displays the list of courses of GFG. Use ArrayAdapter to store the courses list. Create a single MainActivity that contains the spinner and on clicking any item of spinner Toast with that course name will be shown. Step 1: Create a new ProjectTo create a new Project in Android Studio please refer to How to Create/Start a New Project in Android Studio using Kotlin. We are going to use both Java and Kotlin.Step 2: Working with the activity_main.xmlNow open activity_main.xml and insert the below code in it. activity_main.xml: XML <?xml version="1.0" encoding="utf-8"?> <!--Constraint layout which contain Spinner widget--> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/white" tools:context=".MainActivity"> <!--Spinner widget--> <Spinner android:id="@+id/spinner" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingHorizontal="16dp" android:paddingVertical="8dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent"/> </androidx.constraintlayout.widget.ConstraintLayout> Step 3: Working with the MainActivity.ktThere is one activity and hence one Java/Kotlin file for the MainActivity file. Java/Kotlin file for Main Activity, in which Array Adapter is used to bind data to the spinner. We will fill data in the array of strings and bind that data to the spinner. Here is the code: MainActivity File: Java package org.geeksforgeeks.demo; 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 androidx.appcompat.app.AppCompatActivity; public class MainActivity extends AppCompatActivity implements AdapterView.OnItemSelectedListener { // Create array of Strings and store the names of courses private String[] courses = { "C", "Data structures", "Interview prep", "Algorithms", "DSA with java", "OS" }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Take the instance of Spinner and apply OnItemSelectedListener on it Spinner spin = findViewById(R.id.spinner); spin.setOnItemSelectedListener(this); // Create the instance of ArrayAdapter having the list of courses ArrayAdapter<String> ad = new ArrayAdapter<>( this, android.R.layout.simple_spinner_item, courses ); // Set simple layout resource file for each item of spinner ad.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // Set the ArrayAdapter (ad) data on the Spinner which binds data to spinner spin.setAdapter(ad); } @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { // Make toast of the name of the course which is selected in the spinner Toast.makeText(getApplicationContext(), courses[position], Toast.LENGTH_SHORT).show(); } @Override public void onNothingSelected(AdapterView<?> parent) { // No action needed when no selection is made } } Kotlin package org.geeksforgeeks.demo import android.os.Bundle import android.view.View import android.widget.AdapterView import android.widget.AdapterView.OnItemSelectedListener import android.widget.ArrayAdapter import android.widget.Spinner import android.widget.Toast import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity(), OnItemSelectedListener { // create array of Strings // and store name of courses private var courses = arrayOf( "C", "Data structures", "Interview prep", "Algorithms", "DSA with java", "OS" ) override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) // Take the instance of Spinner and // apply OnItemSelectedListener on it which // tells which item of spinner is clicked val spin = findViewById<Spinner>(R.id.spinner) spin.onItemSelectedListener = this // Create the instance of ArrayAdapter // having the list of courses val ad: ArrayAdapter<*> = ArrayAdapter<Any?>(this, android.R.layout.simple_spinner_item, courses ) // set simple layout resource file // for each item of spinner ad.setDropDownViewResource( android.R.layout.simple_spinner_dropdown_item ) // Set the ArrayAdapter (ad) data on the // Spinner which binds data to spinner spin.adapter = ad } override fun onItemSelected(parent: AdapterView<*>?, view: View, position: Int,id: Long) { // make toast of name of course // which is selected in spinner Toast.makeText(applicationContext, courses[position], Toast.LENGTH_SHORT).show() } override fun onNothingSelected(parent: AdapterView<*>?) {} } Output: Create Quiz Comment R Rishabh007 Follow 17 Improve R Rishabh007 Follow 17 Improve Article Tags : Android Kotlin Android Java-Android Explore BasicsIntroduction to Android Development 5 min read History of Android 15+ min read Best Way to Become Android Developer â A Complete Roadmap 7 min read Android Development Prerequisites [2025] - Things to Learn Before Android Development 8 min read Android App Development Fundamentals for Beginners 6 min read Android Architecture 5 min read Android System Architecture 3 min read Android Boot Process 4 min read Difference between Java and Kotlin in Android with Examples 3 min read Interesting Facts About Android 3 min read Software Setup and ConfigurationDownload and Install JDK on Windows, Mac and Linux 6 min read Guide to Install and Setup IntelliJ IDEA for Android App Development 5 min read Guide to Install and Setup Visual Studio for Android App Development 4 min read How to Run the Android App on a Real Device? 2 min read Resolving frequently occurring errors in Android Development 3 min read Android Studio Tutorial 9 min read File Structure & ComponentsComponents of an Android Application 3 min read Introduction to Activities in Android 6 min read Services in Android with Example 10 min read Core TopicsHow Does Android App Work? 7 min read Activity Lifecycle in Android with Demo App 9 min read Introduction to Gradle 4 min read What is Context in Android? 9 min read Bundle in Android with Example 6 min read Activity State Changes In Android with Example 6 min read Processes and Application Lifecycle in Android 7 min read Desugaring in Android 4 min read Difference Between AndroidX and Android Support Libraries 3 min read Memory Leaks in Android 7 min read Layout & ViewLayouts in Android UI Design 3 min read Android UI Layouts 5 min read LinearLayout and its Important Attributes with Examples in Android 3 min read Android LinearLayout in Kotlin 2 min read Android RelativeLayout in Kotlin 4 min read ConstraintLayout in Android 6 min read TextView widget in Android with Examples 5 min read TextView in Kotlin 3 min read Working With the TextView in Android 7 min read Autosizing TextView in Android 6 min read ButtonButton in Android 3 min read How to Add Radio Buttons in an Android Application? 5 min read RadioButton in Kotlin 4 min read How to add Toggle Button in an Android Application 3 min read ToggleButton in Kotlin 2 min read RadioGroup in Kotlin 3 min read Intent and Intent FiltersWhat is Intent in Android? 4 min read Implicit and Explicit Intents in Android with Examples 6 min read How to Send Data From One Activity to Second Activity in Android? 7 min read How to open dialer in Android through Intent? 3 min read Creating Multiple Screen Applications in Android 6 min read How to Open Camera Through Intent and Display Captured Image in Android? 6 min read Toast & RecyclerViewToasts for Android Studio 2 min read What is Toast and How to Use it in Android with Examples? 6 min read Android Toast in Kotlin 3 min read How to Change Toast font in Android? 3 min read How to add a custom styled Toast in Android 4 min read RecyclerView in Android with Example 7 min read Android | Horizontal RecyclerView with Examples 4 min read How to create a nested RecyclerView in Android 5 min read How to Create RecyclerView with Multiple ViewType in Android? 6 min read RecyclerView using ListView in Android With Example 5 min read Fragments & AdaptersIntroduction to Fragments | Android 5 min read Fragment Lifecycle in Android 8 min read How to Create a New Fragment in Android Studio? 2 min read How to Create Swipe Navigation in Android? 6 min read ViewPager Using Fragments in Android with Example 6 min read ArrayAdapter in Android with Example 3 min read SimpleAdapter in Android with Example 7 min read SimpleExpandableListAdapter in Android with Example 10 min read AdapterViewFlipper in Android with Example 5 min read BaseExpandableListAdapter in Android with Example 10 min read Like