background image

      

<item>item2</item>

      

<item>item3</item>

    

</string-array>

  

<resource>

  通过适配器

Adapter 可以设定比较复杂的展示效果,一般项目中比较常用的也是这种

方式。但是如果对于动态的、简单的数据,可以使用

ArrayAdapter 对象来设置适配器,关于

ArrayAdapter 类的介绍,在我的另外一篇博客中有介绍,不了解的朋友可以先看看:
Android--UI 之 AutoCompleteTextView 。

  下面通过一个示例,讲解一下上面说的属性、事件,以及使用

ArrayAdapter 和 XML 资

源文件设定简单数据,代码中注释已经说的很清楚了,这里就不再累述了。

布局代码:

1

 

<?

xml version="1.0" encoding="utf-8"

?>

 

2

 

<

LinearLayout 

xmlns:android

="http://schemas.android.com/apk/res/android"

 

3

 

   android:layout_width

="match_parent"

 

4

 

   android:layout_height

="match_parent"

 

5

 

   android:orientation

="vertical"

 

>

 

6

 

 

7

     

<

TextView

 

8

         

android:layout_width

="wrap_content"

 

9

 

       android:layout_height

="wrap_content"

10

 

       android:text

="弹出的 Spinner"

 

/>

11

 

12

     

<

Spinner

13

         

android:id

="@+id/spinnerBase"

14

 

       android:layout_width

="match_parent"

15

 

       android:layout_height

="wrap_content"

16

 

       android:spinnerMode

="dialog"

 

/>

17

 

18

     

<

TextView

19

         

android:layout_width

="wrap_content"

20

 

       android:layout_height

="wrap_content"