文字列表
目标效果:
运行显示下拉列表,点击可展开,点击子项目会将子项目显示到横线上,并且在TextView中显示选择的城市。
1.activity_main.xml页面添加Spinner控件。
activity_main.xml页面:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<TextView
android:id="@+id/tvShow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp" />
<Spinner
android:id="@+id/spDwon"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/tvShow"
android:layout_marginTop="36dp" />
</RelativeLayout>
2.MainActivity.java页面进行数据源的定义和适配器的配置。
MainActivity.java页面:
package com.example.downshow;
import j

本文介绍了如何在Android应用中使用Spinner控件创建下拉列表,实现点击展开、选择子项目后在TextView中显示所选城市的效果。主要涉及Activity、适配器和下拉列表的配置。

8546

被折叠的 条评论
为什么被折叠?



