Define string array

Download android eBook

Example

In order to define a string array write in a resources file

res/values/filename.xml

<string-array name="string_array_name">
    <item>text_string</item>
    <item>@string/string_id</item>
</string-array>

for example

res/values/arrays.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string-array name="string_array_example">
        <item>@string/app_name</item>
        <item>@string/hello_world</item>
    </string-array>
</resources>

and use it from java like

String[] strings = getResources().getStringArray(R.array.string_array_example;
Log.i("TAG",Arrays.toString(strings)));

Output

I/TAG: [HelloWorld, Hello World!]

Stats

Contributors: 1
2016-01-15
Licensed under: CC-BY-SA

Not affiliated with Stack Overflow
Rip Tutorial: info@zzzprojects.com

Download eBook