在values建立arrays(名字可自定义)的xml:
1 <?xml version="1.0" encoding="utf-8"?> 2 <resources> 3 4 <string-array name="mydata"> 5 <item>hello</item> 6 <item>world</item> 7 </string-array> 8 9 <integer-array name="mydata1"> 10 <item>1</item> 11 <item>2</item> 12 </integer-array> 13 14 </resources>
java中调用
1 package com.example.array; 2 3 import android.app.Activity; 4 import android.os.Bundle; 5 import android.util.Log; 6 7 8 public class MainActivity extends Activity { 9 10 @Override 11 protected void onCreate(Bundle savedInstanceState) { 12 super.onCreate(savedInstanceState); 13 setContentView(R.layout.activity_main); 14 15 String[] data=this.getResources().getStringArray(R.array.mydata); 16 Log.d("",data[0]); 17 Log.d("",data[1]); 18 19 Log.d("",this.getResources().getStringArray(R.array.mydata)[0]); 20 21 22 int[] data2=this.getResources().getIntArray(R.array.mydata1); 23 Log.d("",data2[0]+""); 24 } 25 26 }