04 Spinner 列表选中
2024-08-26 14:31:13
<span style="font-size:18px;">
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <!--
android:prompt=""设置标题 设置弹出模式时可以看 必须要写入string.xml中然后调用
android:popupBackground=""弹出窗口的背景
android:entries="" 要在string写入string-array
<string-array name="book">
<item>红楼梦</item>
<item>三国演义</item>
<item>桃花林</item>
</string-array>
android:spinnerMode="dialog" 模式 对话框
"dropdown"下拉列表
-->
<Spinner
android:id="@+id/spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:entries="@array/book"
android:spinnerMode="dropdown"
android:prompt="@string/app_name1"
/> </LinearLayout></span>
package com.fmy.a; import android.app.Activity;
import android.os.Bundle;
import android.view.View;<span style="display: none; width: 0px; height: 0px;" id="transmark"></span>
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.Spinner; public class MainActivity extends Activity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.demo_textview);
Spinner s = (Spinner) findViewById(R.id.spinner);
s.setOnItemSelectedListener(new OnItemSelectedListener() { /**
* parent指代Spinner s对象
* view 被选中的子元素
* position 被选中的元素的位置
* id被选中子元素的id
*/
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
} @Override
public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub }
});
} }
最新文章
- php中的gethostbyname函数有问题
- 微信、qq信息汇总、回复(一)
- java多线程学习-同步(synchronized)
- 在XcodeGhost事件之后,获取更纯净的Xcode的方法。
- svn服务端配置
- 如何使用 Microsoft Azure Media Services 现场直播,(Live Streaming) 直播流媒体系统
- MongoDB - Introduction of the mongo Shell
- PowerShell 管道和对象成员
- send()和recv()函数详解
- BZOJ 1509: [NOI2003]逃学的小孩( 树形dp )
- 使用C#开发ActiveX控件
- Ionic集成ArcGIS JavaScript API.md
- Html行内元素和块级元素
- 【Android 应用开发】Android之Bluetooth编程
- PostGreSQL(1)-源码安装
- 数据库中,表一sum得出一个值,赋给表二的某个字段,为null
- Copycat - command
- Python 实例变量
- [Visual Studio] 记一次排错:打不开 Nuget 包管理器里的安装package页面,无法 安装 / 恢复 包
- Qt中使用的C++知识和技能-你必须要了解的