---
title: "Android开发中如何定义和使用数组"
author: "yutinglong"
date: "2011-03-02T17:12:20Z"
tags: []
categories: ["移动开发"]
slug: "android"
draft: false
lastmod: "2011-03-02T17:12:20Z"
id: 938533
url: "https://yutinglong.iteye.com/blog/938533"
---

数组在Android开发中是如何定义和使用的呢？  
在Android学习中如何定义和使用数组呢，请看下面的代码！

```
<resources> 
    <!-- Used in View/Spinner1.java --> 
    <string-array name="colors"> 
        <item>red</item> 
        <item>orange</item> 
        <item>yellow</item> 
        <item>green</item> 
        <item>blue</item> 
        <item>violet</item> 
    </string-array> 
</resources> 

```

 

```
Resources res = this.getResources(); 
String[] arr = res.getStringArray(R.array.colors); 
for(int i=0; i<arr.length-1; i++) { 
        Log.i("TEST", arr[i]); 
}
```