java - Android Resource - Array of Arrays -
i trying implement resource data structure includes array of arrays, strings. issue run how sub-array objects , specific values. here resource file looks like....
<resources> <array name="array0"> <item> <string-array name="array01"> <item name="id">1</item> <item name="title">item one</item> </string-array> </item> <item> <string-array name="array02"> <item name="id">2</item> <item name="title">item two</item> </string-array> </item> <item> <string-array name="array03"> <item name="id">3</item> <item name="title">item three</item> </string-array> </item> </array> </resources>
then, in java code retrieve array , try access sub elements so...
typedarray typedarray = getresources().obtaintypedarray(r.array.array0); typedvalue typedvalue = null; typedarray.getvalue(0, typedvalue);
at point typedarray object should represent string-array "array01", however, don't see how retrieve "id" , "title" string elements. appreciated, in advance.
you can want. have declare each array separately , array of references. this:
<string-array name="array01"> <item name="id">1</item> <item name="title">item one</item> </string-array> <!-- etc. --> <array name="array0"> <item>@array/array01</item> <!-- etc. --> </array>
then in code this:
resources res = getresources(); typedarray ta = res.obtaintypedarray(r.array.array0); int n = ta.length(); string[][] array = new string[n][]; (int = 0; < n; ++i) { int id = ta.getresourceid(i, 0); if (id > 0) { array[i] = res.getstringarray(id); } else { // wrong xml } } ta.recycle(); // important!
Comments
Post a Comment