0

In code, it's easy to use the Resources class to get an instance of an XML typed array resource and traverse its items. My question: is it possible to reference array resource items in XML itself as shown below

<resource> <array name="items"> <item>Item One</item> <item>Item Two</item> <item>Item Three</item> </array> <string name="itemThree">@array/items[2]</string> </resource> 

The format shown above does not work. Does anyone know if that is possible using a different format?

2 Answers 2

1

No, but I think the reverse works. Define your strings as string resources and refer to them as @string/... in the <item> elements.

Sign up to request clarification or add additional context in comments.

Comments

1

I would just define itemThree in Java:

String itemThree = getResources().getStringArray(R.array.items)[2] 

Ultimately, the XML gets inflated into Java objects, so it's not much difference IMO.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.