Array of String in Android Resources

May 14, 2019

Declare string array in res/values/strings.xml.

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string-array name="messages">
        <item>Hello</item>
        <item>Good day</item>
        <item>Hi</item>
    </string-array>
</resources>

Extract string array by code.

val messages = context.resources.getStringArray(R.array.messages)for (message in messages) {}

NOTE: If R.array doesn't appear, make sure you are acessing the correct R (<PACKAGE_NAME>.R)

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.