Click here to Skip to main content
13,057,089 members (44,313 online)
Click here to Skip to main content
Add your own
alternative version


11 bookmarked
Posted 10 Apr 2014

How to Populate a Spinner (Dropdown/Picklist) with Values in Android

, 19 May 2014
Rate this:
Please Sign up or sign in to vote.
Easily create and hook up values to display in an Android Spinner

Then Came Cervantes / Could It Be I'm Working My Way Back to La Mancha, Babe

To populate a Spinner (in other environments known as a dropdown or a picklist or so), follow these simple steps:

Open your project's arrays.xml file that should live below ...\app\src\main\res\values\

Add some items in a string-array section like so:

<string-array name="quixote_characters">
    <item>Don Quixote</item>
    <item>Sancho Panza</item>
    <item>Teresa Panza</item>
    <item>Dulcinea del Toboso</item>
    <item>Cide Hamete Benengeli</item>
    <item>Mambrino's Helmet</item>
    <item>La Mancha</item>
</string-array> that it looks like this:

Add a Spinner to any Layout file (in Droidio (Android Studio), simply drag-and-drop a Spinner onto the image of the device to be emulated).

Alternatively, you can add the code directly by pasting in the following XML, and then modifying as necessary:




        android:id="@+id/spinnerQuixote" />

Then add this line to the XML:

android:entries="@array/quixote_characters" that Spinner's XML to hook the values added above to the Spinner. In context, that looks like this:








        android:layout_alignParentStart="true" /> that when you run it, it looks like so:

An Embarrassment of Spoils

As a bonus, here is the code necessary to assign the selected value from the Spinner to a String variable:

final Spinner spin = (Spinner) findViewById((;
final String spinVal = String.valueOf(spin.getSelectedItem());

Respect the Strength of My Mighty Arm!

If you like this tip, send me Mambrino's helmet, or at least a reasonable facsimile thereof (perhaps via clever usage of a 3D printer).

OR! You could purchase the Kindle edition (over 2,600 pages) in Spanish and English, paragraph-by-paragraph of Don Quixote.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

B. Clay Shannon
Founder Across Time & Space
United States United States
I am in the process of morphing from a software developer into a portrayer of Mark Twain. My monologue (or one-man play, entitled "The Adventures of Mark Twain: As Told By Himself" and set in 1896) features Twain giving an overview of his life up till then. The performance includes the relating of interesting experiences and humorous anecdotes from Twain's boyhood and youth, his time as a riverboat pilot, his wild and woolly adventures in the Territory of Nevada and California, and experiences as a writer and world traveler, including recollections of meetings with many of the famous and powerful of the 19th century - royalty, business magnates, fellow authors, as well as intimate glimpses into his home life (his parents, siblings, wife, and children).

Peripatetic and picaresque, I have lived in eight states; specifically, besides my native California (where I was born and where I now again reside) in chronological order: New York, Montana, Alaska, Oklahoma, Wisconsin, Idaho, and Missouri.

I am also a writer of both fiction (for which I use a nom de plume, "Blackbird Crow Raven", as a nod to my Native American heritage - I am "½ Cowboy, ½ Indian") and nonfiction, including a two-volume social and cultural history of the U.S. which covers important events from 1620-2006:

You may also be interested in...


Comments and Discussions

QuestionPopulate Default Spinner Value withText File Pin
Member 996588218-Jan-15 8:07
memberMember 996588218-Jan-15 8:07 
AnswerRe: Populate Default Spinner Value withText File Pin
B. Clay Shannon18-Jan-15 8:47
professionalB. Clay Shannon18-Jan-15 8:47 
Questionproblems Pin
Andre Luiz V Sanches10-Apr-14 20:40
memberAndre Luiz V Sanches10-Apr-14 20:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170728.6 | Last Updated 20 May 2014
Article Copyright 2014 by B. Clay Shannon
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid