SoFunction
Updated on 2025-04-12

Simple use of parsing string-array data source in Android

In Android, using string-array is a simple method to extract XML resource file data.
Examples are as follows:
Put the corresponding data into the values ​​folder file
Copy the codeThe code is as follows:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string-array name="city">
<item>Xiamen City</item>
<item>Fuzhou City</item>
<item>Quanzhou City</item>
<item>Zhangzhou City</item>
<item>Longyan City</item>
    </string-array> 
</resources>

Then in the Activity, use it directly
Resources res =getResources();
String[] city=();
You can obtain all item data under string-array name="city", a simple and convenient method.