Paul Hopkinson
Paul Hopkinson

Reputation: 441

Android Spinner Guidance

I'm trying to create an android drop down box but finding it difficult to find a suitable example that isn't overly complicated.

What I want is a simple drop down box with 4 or 5 options in it. Those options should be placed in an xml file that the spinner reads in.

All the examples have dealt with multiple spinners on a page of seem to have bloated code that doesn't make sense.

Upvotes: 0

Views: 234

Answers (2)

Yonah Karp
Yonah Karp

Reputation: 671

In res > Values > Strings

<string-array name="mySpinnerOptions">
    <item>Cow</item>
    <item>Dog</item>
    <item>Cat</item>
    <item>Horse</item>
</string-array>

In your content_myView file

<Spinner
    android:id="@+id/mySpinner"
    android:entries="@array/mySpinnerOptions"
    android:layout_width="your_width"
    android:layout_height="your_height"/>

Upvotes: 1

simplegr33n
simplegr33n

Reputation: 130

Here's a simple example that you can get the gist of from steps 1 and 2.

https://www.mkyong.com/android/android-spinner-drop-down-list-example/

Summary:

  1. Create string array in strings.xml

  2. Add android:entries="@array/your_array" to your Spinner component in your layout xml

Upvotes: 0

Related Questions