More to the original question.. You might just want to skip the
ArrayList and do something like this, from ApiDemos/src/com/example/
android/apis/view/Spinner1.java:

Spinner s1 = (Spinner) findViewById(R.id.spinner1);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource
(this, R.array.colors, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource
(android.R.layout.simple_spinner_dropdown_item);
s1.setAdapter(adapter);


On Mar 9, 4:31 pm, mafro <[email protected]> wrote:
> Taking an example from the Dev Guide - you can do it like this:
>
> http://d.android.com/guide/samples/ApiDemos/res/values/arrays.html
>
> In res/values/arrays.xml:
> <resources>
>     <!-- Used in View/Spinner1.java -->
>     <string-array name="colors">
>         <item>red</item>
>         <item>orange</item>
>         <item>yellow</item>
>         <item>green</item>
>         <item>blue</item>
>         <item>violet</item>
>     </string-array>
> </resources>
>
> //java code
> Resources res = this.getResources();
>
> String[] arr = res.getStringArray(R.array.colors);
> for(int i=0; i<arr.length-1; i++) {
>         Log.i("TEST", arr[i]);
>
> }
>
> So R.array.colors is your reference. You can create an ArrayList and
> add this array to it if necessary.
>
> mafro
>
> Videoguy wrote:
> > Is is possible to specify data in xml resource file and initialize
> > ArrayList from it?
> > I am looking for a way to use the ArrayList with a SimpleAdapter to
> > bind to a ListView.
> > I am wondering if there is a way to specify my data in xml resource
> > file and init ArrayList from it.
>
> > Videoguy
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to