0

I have a string array in strings.xml as detailed below:

<string-array name="spinerArray">
    <item name="one">First</item>
    <item name="two">Second</item>
    <item name="three">Third</item>
    <item name="four">Fourth</item>
</string-array>

And I need to retrieve one of the items name not the value (one, two, three, four). So far, I know it's possible to get the name of the array using getResourceEntryName like:

getResources().getResourceEntryName(R.array.spinerArray);

Is there a way to get an item name?

Thanks.

alezvic
  • 344
  • 1
  • 4
  • 20
  • A question similar to this has been answered. [Here](http://stackoverflow.com/questions/7224926/how-to-get-name-attribute-of-item-of-string-array) is a link to it that may be helpful. – Ryan Smith Aug 20 '13 at 16:07

2 Answers2

0

As this is an xml, you will need a xml parser. Then you can get the values of name using

attributes.getValue("name");

Or

name = ((Element) your_node).getAttribute("name"));
using DOM parser (org.w3c.dom)
Ritesh Gune
  • 16,629
  • 6
  • 44
  • 72
0

Another solution:

Resources res = getResources();
TypedArray entriesTypedArray = res.obtainTypedArray(R.array.spinerArray);
ArrayList entriesName = new ArrayList();
TypedValue v1 = new TypedValue();
for (int i1=0; i1<entriesTypedArray.length(); i1++) {
    entriesTypedArray.getValue(i1, v1);
    String name1 = res.getResourceEntryName(v1.resourceId);
    entriesName.add(name1);
}
Dennis
  • 1
  • 1