Android中定义数组与使用

来源:互联网 发布:淘宝店主发快递多少钱 编辑:程序博客网 时间:2024/04/29 06:17
Android学习中如何定义和使用数组呢,请看下面的代码!
    <?xml version="1.0" encoding="utf-8"?><resources>    <string-array name="colors">        <item>黑色 | Black</item>        <item>蓝色 | Blue</item>        <item>棕色 | Brown</item>        <item>绿色 | Green</item>        <item>灰色 | Grey</item>        <item>粉色 | Pink</item>        <item>紫色 | Purple</item>        <item>红色 | Red</item>        <item>白色 | White</item>        <item>黄色 | Yellow</item>    </string-array></resources>


  1. //java code
  2. Resources res = this.getResources();


  3. String[] arr = res.getStringArray(R.array.colors);
  4. for(int i=0; i<arr.length-1; i++) {
  5.         Log.i("TEST", arr);

  6. }