android 控件 下拉列表(Spinner)

来源:互联网 发布:录制搞笑视频软件 编辑:程序博客网 时间:2024/05/16 05:13

1、继承关系和子类:


2、定义:

A view that displays one child at a time and lets the user pick among them. The items in the Spinner come from the Adapter associated with this view.\

3、XML重要属性:

setOnItemSelectedListener

4、重要方法:

5、实战:

布局文件 

5.1最简单的实现

布局文件

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:id="@+id/container"    android:layout_width="match_parent"    android:layout_height="match_parent"android:orientation="vertical"    tools:ignore="MergeRootLinear">    <TextView        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:text="下拉列表" />    <Spinner         android:layout_width="match_parent"        android:layout_height="wrap_content"        android:entries="@array/citys"        /></LinearLayout>

设置数据 直接在xml文件中设置,也可以在java代码中使用adapter

<?xml version="1.0" encoding="utf-8"?><resources>    <string name="app_name">SpinnerDemo</string>    <string name="hello_world">Hello world!</string>    <string name="action_settings">Settings</string>    <string-array name="citys">        <item >北京</item>        <item >上海</item>        <item >廣州</item>        <item >深圳</item>    </string-array></resources>

参考1:http://developer.android.com/intl/zh-cn/reference/android/widget/Spinner.html
参考2:http://www.open-open.com/lib/view/open1330651497624.html
0 0