Android 编程下string-array 的使用

在实际开发中,当数据为固定数据、数据量不是很大、希望很方便的获取到这些数据的时候,可以考虑使用这种低成本的方式来获取预装数据。将想要保存的数据存储到 values 文件夹下的 arrays.xml 文件中,格式如下:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string-array name="city">
          <item>北京</item>
          <item>天津</item>
          <item>太原</item>
          <item>西安</item>
          <item>郑州</item>
      </string-array>
</resources>

然后在应用中通过以下方式即可获取到 namecity 数组集下的所有数据:

Resources res = getResources();
String[] city = res.getStringArray(R.array.city);
原文地址:https://www.cnblogs.com/sunzn/p/3395998.html