Parsing the simple use of string array data sources in Android

  • 2020-05-10 18:51:16
  • OfStack

In Android, using string-array is a simple way to extract data from XML resource files.
Examples are as follows:
Put the corresponding data in the arrays.xml file in the values folder

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <string-array name="city"> 
        <item> Xiamen, </item> 
        <item> fuzhou </item> 
        <item> Quanzhou city </item> 
        <item> zhangzhou </item> 
        <item> Longyan. </item> 
    </string-array>  
</resources>

And then in Activity, you use it directly
Resources res =getResources();
String[] city=res.getStringArray(R.array.city);
All item data under string-array name="city" can be obtained. This is a simple and convenient method.

Related articles: