首页 > 代码库 > values文件下数组的读取
values文件下数组的读取
package com.example.testarrays;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity extends Activity {
private TextView tv;
private String[] strArr;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv = (TextView) findViewById(R.id.textView01);
/**
* 获取arrays。xml中名称为groups的项
* 并放在数组strArr中
* */
strArr = this.getResources().getStringArray(R.array.groups);
initData();
}
private void initData(){
for(int i=0; i<strArr.length; i++){
tv.setText(tv.getText() + strArr[i] + "\n");
}
}
}
//arrays.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="groups">
<item>天龙八部</item>
<item>射雕英雄传</item>
<item>神雕侠侣</item>
</string-array>
</resources>
本文出自 “爬过山见过海” 博客,请务必保留此出处http://670176656.blog.51cto.com/4500575/1565876
values文件下数组的读取