Reputation: 441
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
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
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:
Create string array in strings.xml
Add android:entries="@array/your_array"
to your Spinner component in your layout xml
Upvotes: 0