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?

basickarl
  • 37,187
  • 64
  • 214
  • 335

2 Answers2

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.

ialfa1987
  • 83
  • 7
  • Ok so I use the metod to put the data into a String[], How do I extract, let's say, the flag property now? – basickarl Jul 06 '14 at 21:13
  • 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). – ialfa1987 Jul 06 '14 at 21:15
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

Community
  • 1
  • 1
DArkO
  • 15,880
  • 12
  • 60
  • 88