Android学习笔记_72_Spinner的用法
一、普通
1、
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:gravity="left"
android:paddingLeft="8dip"
android:singleLine="true"
android:textSize="12sp"
android:textStyle="bold"
android:textColor="@color/gsdk_black"
android:text="sdf" />
2
private String[] method = null;
ArrayAdapter<String> methodAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, method);
methodSpinner = (Spinner) findViewById(R.id.spinner_recharge_type);
moneyAdapter
.setDropDownViewResource(android.R.layout.select_dialog_item);
methodSpinner.setAdapter(methodAdapter);
二、自定义spinner:
1、配置文件:
<?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="wrap_content"
android:orientation="horizontal" > <TextView
android:id="@+id/tv_spinner_id"
android:layout_width="60dp"
android:layout_height="80dp"
android:visibility="gone" /> <TextView
android:id="@+id/tv_spinner_name"
style="?android:attr/spinnerDropDownItemStyle"
android:layout_width="match_parent"
android:layout_height="35dip"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:textColor="#000"
android:textSize="@dimen/font_body" /> </LinearLayout>
2、填充数据
List<Map<String, Object>> data = new ArrayList<Map<String, Object>>();
for (Project project : linkedList) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("name", project.getName());
map.put("id", project.getId());
data.add(map);
}
searchAdapter = new SimpleAdapter(PurchaseActivity.this, data,
R.layout.purchase_search_spinner, new String[]{"id","name"},
new int[]{R.id.tv_spinner_id,R.id.tv_spinner_name});
searchSpinner.setAdapter(searchAdapter);
3、点击事件:注意点击事件是OnItemSelectedListener而不是OnItemClickListener.
private class SearchSpinnerItemListener implements OnItemSelectedListener{
@Override
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
Spinner spinner = (Spinner) parent;
Map<String, Object> projectMap = (Map<String, Object>) spinner.getItemAtPosition(position);
int pid = Integer.valueOf(projectMap.get("id")+"");
String pname = (String) projectMap.get("name");
Log.i("Purchase","pid: "+pid+" pname: "+pname);
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
}
Android学习笔记_72_Spinner的用法的更多相关文章
- Android 学习笔记之Volley(七)实现Json数据加载和解析...
学习内容: 1.使用Volley实现异步加载Json数据... Volley的第二大请求就是通过发送请求异步实现Json数据信息的加载,加载Json数据有两种方式,一种是通过获取Json对象,然后 ...
- Android学习笔记进阶之在图片上涂鸦(能清屏)
Android学习笔记进阶之在图片上涂鸦(能清屏) 2013-11-19 10:52 117人阅读 评论(0) 收藏 举报 HandWritingActivity.java package xiaos ...
- android学习笔记36——使用原始XML文件
XML文件 android中使用XML文件,需要开发者手动创建res/xml文件夹. 实例如下: book.xml==> <?xml version="1.0" enc ...
- Android学习笔记之JSON数据解析
转载:Android学习笔记44:JSON数据解析 JSON(JavaScript Object Notation)是一种轻量级的数据交换格式,采用完全独立于语言的文本格式,为Web应用开发提供了一种 ...
- udacity android 学习笔记: lesson 4 part b
udacity android 学习笔记: lesson 4 part b 作者:干货店打杂的 /titer1 /Archimedes 出处:https://code.csdn.net/titer1 ...
- jQuery学习笔记之Ajax用法详解
这篇文章主要介绍了jQuery学习笔记之Ajax用法,结合实例形式较为详细的分析总结了jQuery中ajax的相关使用技巧,包括ajax请求.载入.处理.传递等,需要的朋友可以参考下 本文实例讲述了j ...
- Android学习笔记36:使用SQLite方式存储数据
在Android中一共提供了5种数据存储方式,分别为: (1)Files:通过FileInputStream和FileOutputStream对文件进行操作.具体使用方法可以参阅博文<Andro ...
- Android学习笔记之Activity详解
1 理解Activity Activity就是一个包含应用程序界面的窗口,是Android四大组件之一.一个应用程序可以包含零个或多个Activity.一个Activity的生命周期是指从屏幕上显示那 ...
- Pro Android学习笔记 ActionBar(1):Home图标区
Pro Android学习笔记(四八):ActionBar(1):Home图标区 2013年03月10日 ⁄ 综合 ⁄ 共 3256字 ⁄ 字号 小 中 大 ⁄ 评论关闭 ActionBar在A ...
随机推荐
- Beam编程系列之Apache Beam WordCount Examples(MinimalWordCount example、WordCount example、Debugging WordCount example、WindowedWordCount example)(官网的推荐步骤)
不多说,直接上干货! https://beam.apache.org/get-started/wordcount-example/ 来自官网的: The WordCount examples demo ...
- 024-cxf.xml配置文件模板
版本一 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://ww ...
- NSTimer循环引用的问题
前言: 记得之前看过一个面试题问:ARC环境下的dealloc方法有什么用?问题解答是:代理指针置空,停止定时器timer,注销通知,释放掉实例变量.看着没什么问题,而且网上一收也是大概这样的答案.今 ...
- pythion的定义函数和传递实参
1.定义函数 例子: def greet_user(): """显示简单的问候语""" print("Hello!")g ...
- How can I use Server.MapPath() from global.asax?
引用: using System.Web.Hosting; string filePathcsv = ""; string file = ""; string ...
- vue——介绍和使用
一.vue介绍 vue官网说:Vue.js(读音 /vjuː/,类似于 view) 是一套构建用户界面的渐进式的JavaScript框架.与其他重量级框架不同的是,Vue 采用自底向上增量开发的设计. ...
- for计算位置坐标
代码1效果图: 代码2效果图: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"&g ...
- matlab练习程序(旋转、径向模糊)
还记得过去写过径向模糊,不过当时效果似乎不好. 这次效果还可以,程序中用的算法是: 1.求当前处理点和图像中心点之间的距离r与角度ang; 2.通过对r的修改得到径向模糊. 3.通过对ang的修改得到 ...
- Python tqdm show progress bar
tqdm can help to show a smart progress bar, and it is very easy to use, just wrap any iterable with ...
- day009-IO流
什么叫流?就是数据的流动.以内存为基准,分为输入input和输出output.输入也叫做读取数据,输出也叫写出数据. 分类 按数据的流向分: 输入流.输出流 按数据类型分: 字节流.字符流 1. ...