java - String Array in res/values/strings.xml -


i know how create array of strings inside strings.xml, , how access in java code. need in order use settext(). please help.

strings.xml

 <?xml version="1.0" encoding="utf-8"?>  <resources> <string-array name="planets_array"> // name of string array     <item>mercury</item> // items     <item>venus</item>     <item>earth</item>     <item>mars</item> </string-array> </resources> 

in activity class.

  resources res = getresources();    string[] planets = res.getstringarray(r.array.planets_array);                   or    string[] planets = getresources().getstringarray(r.array.planets_array); 

getresource requires activity context. if in non activity class need activity context can passed non activity class contructor.

source @

http://developer.android.com/guide/topics/resources/string-resource.html#stringarray

edit:

  new customadapter(activityname.this); 

then

  class customadapter extends baseadapter   {       context mcontext;       public customadapter(context context)       {            mcontext = context;       }    ...// rest of code   } 

use mcontext.getresources()


Comments