Android学习笔记之SimpleAdapter
来源:互联网 发布:大数据如何获取及用途 编辑:程序博客网 时间:2024/05/07 23:10
这是一个简单的适配器,可以将静态数据映射到XML文件中定义好的视图。你可以指定数据支持的列表如ArrayList组成的Map。在ArrayList中的每个条目对应List中的一行。Maps包含每行数据。你可以指定一个定义了被用于显示行的视图XML文件,通过关键字映射到指定的视图。绑定数据到视图分两个阶段,首先,如果一个SimpleAdapter.ViewBinder是有效的,setViewValue(android.view.View, Object, String)将被调用。如果返回值是真,绑定完成了。如果返回值为假,下面的视图将按以下顺序去处理:
一个实现了Checkable的视图(例如CheckBox),期望绑定值是一个布尔类型。
TextView期望绑定值是一个字符串类型,通过调用setViewText(TextView, String)绑定。
ImageView期望绑定值是一个资源id或者一个字符串,通过调用setViewImage(ImageView, int) 或 setViewImage(ImageView, String)。
如果没有一个合适的绑定发生将会抛出IllegalStateException。
publicSimpleAdapter(Context context,List<? extendsMap<String, ?>> data, int resource, String[] from, int[] to)
构造函数
参数
context 关联SimpleAdapter运行着的视图的上下文。
data 一个Map的列表。在列表中的每个条目对应列表中的一行,应该包含所有在from中指定的条目
resource 一个定义列表项目的视图布局的资源唯一标识。布局文件将至少应包含哪些在to中定义了的名称。
from 一个将被添加到Map上关联每一个项目的列名称的列表
to 应该在参数from显示列的视图。这些应该全是TextView。在列表中最初的N视图是从参数from中最初的N列获取的值。
package android.imageview;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;import android.app.Activity;import android.os.Bundle;import android.view.View;import android.widget.AdapterView;import android.widget.AdapterView.OnItemSelectedListener;import android.widget.ArrayAdapter;import android.widget.SimpleAdapter;import android.widget.Spinner;public class ImageView1Activity extends Activity { /** Called when the activity is first created. */private Spinner spinner1 = null;private List<Map<String,Object>> list = null;private SimpleAdapter adapter = null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); list = new ArrayList<Map<String,Object>>(); Map<String,Object> hashmap = new HashMap<String,Object>(); hashmap.put("itemsrc",R.drawable.macos01); hashmap.put("itemname","信息学院"); list.add(hashmap); HashMap<String,Object> hashmap1 = new HashMap<String,Object>(); hashmap1.put("itemsrc",R.drawable.macos04); hashmap1.put("itemname","信电学院"); list.add(hashmap1); HashMap<String,Object> hashmap2 = new HashMap<String,Object>(); hashmap2.put("itemsrc",R.drawable.macos01); hashmap2.put("itemname","经管学院"); list.add(hashmap2); spinner1 = (Spinner)findViewById(R.id.spinner1); spinner1.setPrompt("你要以后在哪工作?"); adapter = new SimpleAdapter(ImageView1Activity.this,list,R.layout.other,new String[]{"itemsrc","itemname"},new int[]{R.id.text1,R.id.text2}); spinner1.setAdapter(adapter); }}
main.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Spinner"/> <Spinner android:id="@+id/spinner1" android:layout_width="fill_parent" android:layout_height="wrap_content"/></LinearLayout>
other.xml
<?xml version="1.0" encoding="utf-8"?><TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TableRow > <ImageView android:id="@+id/text1" android:layout_width="wrap_content" android:layout_height="wrap_content"/> <TextView android:id="@+id/text2" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </TableRow> </TableLayout>
- Android学习笔记之SimpleAdapter
- Android学习笔记之SimpleAdapter
- Android学习笔记之SimpleAdapter
- Android学习笔记之ListView采用SimpleAdapter
- android学习之SimpleAdapter
- android学习笔记29:simpleAdapter
- 安卓学习笔记之SimpleAdapter
- 【Android学习笔记】ListView使用SimpleAdapter适配器
- 【Android学习笔记】Adapter - ArrayAdapter、SimpleAdapter
- 【Android学习笔记】ListView使用SimpleAdapter适配器
- android学习之——simpleadapter
- 学习Android之SimpleAdapter显示网络图片
- Android学习笔记之——ListView 的两种适配器ArrayAdapter和SimpleAdapter
- Android笔记 simpleAdapter demo
- Android学习笔记(八):SimpleAdapter的学习
- Android-SimpleAdapter用法学习
- Android适配器之-----SimpleAdapter
- android之SimpleAdapter
- HTML5 实现小车动画效果(Canvas/CSS3/JQuery)
- OpenCV像素点处理
- POJ 1595 Prime Cuts(我的水题之路——素数取中间区域,准确定位)
- Win7下Orcad16.3与PADS9.3都安装后Capture提示找不到msvcr90.dll的问题
- 演练:用可视化Web开发器创建基本Web页面
- Android学习笔记之SimpleAdapter
- 咨询工具整理
- 推荐一首歌 《老男孩》
- 获取FileUpload中的上传文件路径
- 一篇文章搞定SqlDataAdapter
- Android模拟器学framework和driver之传感器篇4(Android APP)
- 冷备份---不完全恢复
- asp.net mvc中很酷的jquery验证插件
- 每天一道面试题,为今年找工作早做准备!笨鸟先飞,哈哈(2012年2月篇)