1

I have the following in my res/values/config.xml file

<string-array name="languages">
    <item display="english" code="GB" lang="en" flag="flag_uk" values="en-GB" eng="English (United Kingdom)" />
    <item display="svenska" code="SE" lang="sv" flag="flag_sv" values="sv" eng="Swedish" />
</string-array>

I think you get the picture. I cannot seem to access the item properties. Hows does one do this. Also IS this the correct approach to this?

2 Answers 2

2

This is a string array. You can access the whole of it by using:

getResources().getStringArray()

from a context. It will return a simple array that you can iterate.

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

2 Comments

Ok so I use the metod to put the data into a String[], How do I extract, let's say, the flag property now?
Sorry you can't use the string-array entities like that. "items" don't have any attribute. You'll have to create your own XML file and parse it (do not put the xml file in any values- folder, use a "raw" folder so Android build system will not compile it).
0

You cannot access multiple properties with a string-array in values as far as i know.

But what you see here is XML. you can parse the XML with an XML parser.

What i would suggest as the best option for static data is to have this as an XML file into assets or values/raw and use an XML parser to parse into an array of objects.

Alternatively you can save it as JSON so its easier to parse.

try this:

Android Java; How can I parse a local JSON file from assets folder into a ListView

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.