Android: Load array of Strings from Resources

Android: Load array of Strings from Resources

It is remanded to keep your strings in xml resources, but how do you get them as a String[] ?


Save as a xml file on your project > res > values > mydata.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string-array name="blogs">
        <item>http://www.google.com/</item>
        <item>http://www.yahoo.com/</item>
        <item>http://www.bing.com/</item>
    </string-array>
</resources>

and from your source code

//...
Resources res = this.getResources();
String[] myWebsitesArray= res.getStringArray(R.array.websites);
//...

that is it.

No comments.