Jeremy Jeremy - 1 year ago 61
Android Question

Use string array to populate Spinner

I'm in the rookie leagues when it comes to Android apps and am looking to populate a Spinner with an Array or strings (it's a converter app) below is an extract from my XML file and I'm looking to populate the the Spinner:

<string name="TemperatureString">Temperature</string>
<string name="WeightString">Weight</string>
<string name="VolumeString">Volume</string>
<string name="SpeedString">Speed</string>
<string name="LengthString">Length</string>
<string name="AreaString">Area</string>
<string name="EnergyString">Energy</string>
<string name="PresureString">Presure</string>
<string name="MemoryString">Memory</string>

<string-array name="Convert_Type">

From this, I'm trying to populate my spinner (
) - I'm not sure what I'm doing here but for the
I have the following:


I know there's a way of doing this via Java but I'm even worse at Java!
For this reason, I'd like to keep this within xml if possible.

Also, If someone can want's to point me towards links to bring on my Java and xml skills that would be great - I've started with Udacity and have found them good but there's a lot to take in for a non-IT graduate (I work in finance but find this kinda thing really interesting!)

Thanks in advance!

Answer Source

Simplest way to bind ListView and Spinner control with String Array is

android:entries = "@array/nameofarray"


If you want to change the theme of each item of Spinner then put below style into res/values/styles.xml

<style name="ItemTextAppearance">
    <item name="android:textColor">#f00</item>
    <item name="android:textStyle">bold</item>
    <item name="android:typeface">monospace</item>

and the set


of spinner.