ArrayAdapter、SimpleAdapter简单用法
1. 使用流程

2. ArrayAdapter
new ArrayAdapter<?>(context, textViewResourceId, objects)
context:上下文
textViewResourceId:列表项的布局文件id
objects:数据源(数组或集合)
public class MainActivity extends Activity {
private ListView myListView;
private ArrayAdapter<String>arrayAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//新建数据源
String[] data = {"初探ListView","初探ListView","初探ListView","初探ListView"};
//新建适配器并绑定数据源
adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, data);
//设置适配器
myListView = (ListView) findViewById(R.id.myListView);
myListView.setAdapter(arrayAdapter);
}
}
3. SimpleAdapter
new SimpleAdapter(context, data, resource, from, to)
context:上下文
data:List> data,数据源必须是一个泛型为Map<String, ?>的集合。其中,集合中的每一个Map对应ListView中的一项。
resource:列表项的布局文件id
from:Map中的键名
to:列表项的布局文件中的组件id
public class MainActivity extends Activity {
private ListView myListView;
private SimpleAdapter simpleAdapter;
private List<Map<String, Object>> data;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//新建数据源
data = new ArrayList<Map<String, Object>>();
for (int i = 0; i < 20; i++) {
Map<String, Object>map = new HashMap<String, Object>();
map.put("img", R.mipmap.ic_launcher);
map.put("text", "初识simpleAdapter");
data.add(map);
}
//新建适配器并绑定数据源
simpleAdapter = new SimpleAdapter(this, getData(), R.layout.item, new String[]{"img", "text"}, new int[]{R.id.img, R.id.text});
//设置适配器
myListView = (ListView) findViewById(R.id.myListView);
myListView.setAdapter(simpleAdapter);
}
}
ArrayAdapter、SimpleAdapter简单用法的更多相关文章
- listActivity和ExpandableListActivity的简单用法
http://www.cnblogs.com/limingblogs/archive/2011/10/09/2204866.html 今天自己简单的总结了listActivity和Expandable ...
- Android—— ListView 的简单用法及定制ListView界面
一.ListView的简单用法 2. 训练目标 1) 掌握 ListView 控件的使用 2) 掌握 Adapter 桥梁的作用 实现步骤: 1)首先新建一个项目, 并让ADT 自动帮我们创建好活动. ...
- CATransition(os开发之画面切换) 的简单用法
CATransition 的简单用法 //引进CATransition 时要添加包“QuartzCore.framework”,然后引进“#import <QuartzCore/QuartzCo ...
- jquery.validate.js 表单验证简单用法
引入jquery.validate.js插件以及Jquery,在最后加上这个插件的方法名来引用.$('form').validate(); <!DOCTYPE html PUBLIC " ...
- NSCharacterSet 简单用法
NSCharacterSet 简单用法 NSCharacterSet其实是许多字符或者数字或者符号的组合,在网络处理的时候会用到 NSMutableCharacterSet *base = [NSMu ...
- ArrayAdapter适配器的用法,模拟QQ发消息界面。
import java.util.ArrayList; import android.app.Activity; import android.content.Context; import andr ...
- [转]Valgrind简单用法
[转]Valgrind简单用法 http://www.cnblogs.com/sunyubo/archive/2010/05/05/2282170.html Valgrind的主要作者Julian S ...
- Oracle的substr函数简单用法
substr(字符串,截取开始位置,截取长度) //返回截取的字 substr('Hello World',0,1) //返回结果为 'H' *从字符串第一个字符开始截取长度为1的字符串 subst ...
- Ext.Net学习笔记19:Ext.Net FormPanel 简单用法
Ext.Net学习笔记19:Ext.Net FormPanel 简单用法 FormPanel是一个常用的控件,Ext.Net中的FormPanel控件同样具有非常丰富的功能,在接下来的笔记中我们将一起 ...
随机推荐
- emWin录音机,含uCOS-III和FreeRTOS两个版本
第12期:录音机配套例子:V6-921_STemWin提高篇实验_录音机(uCOS-III)V6-922_STemWin提高篇实验_录音机(FreeRTOS) 例程下载地址: http://forum ...
- Hive如何处理小文件问题?
一.小文件是如何产生的 1.动态分区插入数据,产生大量的小文件,从而导致map数量剧增. 2.reduce数量越多,小文件也越多(reduce的个数和输出文件是对应的). 3.数据源本身就包含大量的小 ...
- [Swift]LeetCode142. 环形链表 II | Linked List Cycle II
Given a linked list, return the node where the cycle begins. If there is no cycle, return null. Note ...
- [Swift]LeetCode452. 用最少数量的箭引爆气球 | Minimum Number of Arrows to Burst Balloons
There are a number of spherical balloons spread in two-dimensional space. For each balloon, provided ...
- [Swift]LeetCode834. 树中距离之和 | Sum of Distances in Tree
An undirected, connected tree with N nodes labelled 0...N-1 and N-1 edges are given. The ith edge co ...
- 用CSS实现一个抽奖转盘
效果 基本是用CSS实现的,没有用图片,加一丢丢JS.完全没有考虑兼容性. 首先画一个转盘, <!DOCTYPE html> <html lang="en"> ...
- Python 实现获取微信好友信息
最近用闲余时间看了点python,在网上冲浪时发现有不少获取微信好友信息的博客,对此比较感兴趣,于是自己敲了敲顺便记录下来. 一.使用 wxpy 模块库获取好友男比例信息和城市分布. # -*- co ...
- Python内置函数(5)——bin
英文文档: bin(x) Convert an integer number to a binary string. The result is a valid Python expression. ...
- FTP解决连接慢问题
今天发现程序报登录FTP超时,于是便手动登录发现真的慢,于是网上搜便获取大招亲测有效,于是怕忘的我马上记录下来,zzzzzzz!! 如下解决 vim /etc/vsftpd/vsftpd.conf 在 ...
- Android 解压zip文件(支持中文)
过了n多天后,当再次使用原先博客上写的那篇: Android 压缩解压zip文件 去做zip包的解压的时候,出现了原来没有发现的很多问题.首先是中文汉字问题,使用java的zip包不能很好的解决解压问 ...