I have a list of colours
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="white">#FFFFFF</color>
<color name="yellow">#FFFF00</color>
<color name="fuchsia">#FF00FF</color>
<color name="red">#FF0000</color>
<color name="silver">#C0C0C0</color>
<color name="gray">#808080</color>
<color name="olive">#808000</color>
<color name="purple">#800080</color>
<color name="maroon">#800000</color>
<color name="aqua">#00FFFF</color>
<color name="lime">#00FF00</color>
<color name="teal">#008080</color>
<color name="green">#008000</color>
<color name="blue">#0000FF</color>
<color name="navy">#000080</color>
<color name="black">#000000</color>
</resources>
(I took this list from another question someone asked)
What I want to do is get all the color names. I want the list so I can then populate the lot in a spinner. The pseudo code would be like this.
List ofColours = getListOfColors(R.color);
for(int i = 0 ; i < ofColours.size() ; i ++)
{
String colour = getResources().getColor(ofColours.get(i));
addColourToSpinner(colour);
}
What I want is the list of colours. I hope that explains it Cheers for all the help
Why not simply create two arrays in in your
strings.xml
orarrays.xml
. Something like this:You can follow a simple example on developer.android.com here: http://developer.android.com/guide/topics/ui/controls/spinner.html.
This is another tutorial: http://www.dcpagesapps.com/developer-resources/android/21-android-tutorial-spinners?start=1
That should get you started.
I got stuck doing this for my project. It took long time to make this and i hope it helps some people. I ended up combining an example from here
http://www.ipcas.com/blog/2011/12/android-color-picker/
and a color list provided from here
Web colors in an Android color xml resource file
Just delete colors you dont need and make whatever you like. (Alot faster than making your own)
This is my Strings.xml
Next i used the ColorPickerDialog provided by
http://www.ipcas.com/blog/2011/12/android-color-picker/
with this as well.
Hopefully this will save people some time.
Next you launch the dialog,
You can access the list of colors using reflection: