博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Spinner的用法

Posted on 2013-04-17 09:59  孤骊  阅读(429)  评论(0)    收藏  举报

1.构建Spinner

    <Spinner android:id="@+id/spnSex"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:prompt="@string/spnSexPrompt"
        android:spinnerMode="dialog"
        />

其中,promt属性是设置显示在选项列表上方的说明.

2.添加数据

其中,android.R.layout.simple_spinner_dropdown_item为Spinner的下拉项的样式定义,这里用的是预定义的样式文件,也可以自定义一个

Layout文件,然后用adapSexList.setDropDownViewResource(R.layout.你的Layout文件)的方式进行设置。

3.添加监听事件

4.绑定事件

spnSex.setOnItemSelectedListener(spnSexItemSelectedListener);