[TinyTut] - Arrays as XML-Resources
What you learn: You will learn how to specify Arrays in an XML-Resource and how to read them out in your code.
Difficulty: 1 of 5

Description:
Lets take a look at an practical example, which was used in the AndroidFileBrowser 2.0-Tutorial. There we defined the fileEndings for different file-categories(Audio, Text, Images, ...) in an XML-File to make our Application highly generic
You simply have to create an resource of any name (should and with .xml) in your "res/values/"-Directory.
You can define as many Arrays within each file, as you want with as many items you want.
Using xml Syntax Highlighting
- <?xml version="1.0" encoding="utf-8"?>
- <resources>
- <array name="fileEndingImage">
- <item>.png</item>
- <item>.gif</item>
- <item>.jpg</item>
- <item>.jpeg</item>
- <item>.bmp</item>
- </array>
- <array name="fileEndingAudio">
- <item>.mp3</item>
- <item>.wav</item>
- <item>.ogg</item>
- <item>.midi</item>
- </array>
- <array name="fileEndingPackage">
- <item>.jar</item>
- <item>.zip</item>
- <item>.rar</item>
- <item>.gz</item>
- </array>
- <array name="fileEndingWebText">
- <item>.htm</item>
- <item>.html</item>
- <item>.php</item>
- </array>
- </resources>
Parsed in 0.005 seconds, using GeSHi 1.0.8.4
So that was as easy as one can imagine.
Now we surely want to read those "Text"-Arrays into our application as "Real"-Array o fthe Type String. You can do that with the following single line (also from the FileBrowser-Example):
Using java Syntax Highlighting
- String[] myImageFileEndings = getResources().getStringArray(R.array.fileEndingImage)
Parsed in 0.030 seconds, using GeSHi 1.0.8.4
Thats it.

Regards,
plusminus




, but I thought it would really be useful for others and I posted it here... 

