继承SimpleCursorAdapter定制Adapter
2015-12-11 16:10
344 查看
以前对newview 和bindview的理解不是很深,今天特意研究研究。
[java] view
plaincopy
newView 0
bindView 0
newView 1
bindView 1
newView 2
bindView 2
newView 3
bindView 3
newView 4
bindView 4
newView 5
bindView 5
newView 6
bindView 6
newView 7
bindView 7
开始时有多少可以显示的view就执行下多少下newView,后面滚动listview的时候 只执行bindView,除非又可以看到新的item如上面的如果可以看到第8个item的时候,那就要newView.否则都不执行newView,下面是listview滚动的时候的执行log.
[java] view
plaincopy
bindView 8
bindView 9
bindView 10
bindView 11
bindView 12
bindView 13
bindView 14
bindView 15
一般情况SimapleCursorAdapter是用来和数据库有关cursor。一般newView中只负责View的部分,setTag(View)-->只对view,对数据的处理都放在bindView中,不然会有异常情况出现!因为newView在listView滚动的情况下大部分时间不执行,除非上面所说的!总的来说android的用这个就实现了界面更新时候只是更新了数据。而view还是和以前一样。
SimpleCursorAdapter是一个简单的adapter,提供数据库Cursor到TextView的映射。
在实际开发过程中,除了TextView外,往往还需要依赖于数据库数据的其它的组件。
通过继承SimpleCursorAdapter,重写bindView(View view, Context context, Cursor cursor)来实现
[java] view
plaincopy
newView 0
bindView 0
newView 1
bindView 1
newView 2
bindView 2
newView 3
bindView 3
newView 4
bindView 4
newView 5
bindView 5
newView 6
bindView 6
newView 7
bindView 7
开始时有多少可以显示的view就执行下多少下newView,后面滚动listview的时候 只执行bindView,除非又可以看到新的item如上面的如果可以看到第8个item的时候,那就要newView.否则都不执行newView,下面是listview滚动的时候的执行log.
[java] view
plaincopy
bindView 8
bindView 9
bindView 10
bindView 11
bindView 12
bindView 13
bindView 14
bindView 15
一般情况SimapleCursorAdapter是用来和数据库有关cursor。一般newView中只负责View的部分,setTag(View)-->只对view,对数据的处理都放在bindView中,不然会有异常情况出现!因为newView在listView滚动的情况下大部分时间不执行,除非上面所说的!总的来说android的用这个就实现了界面更新时候只是更新了数据。而view还是和以前一样。
SimpleCursorAdapter是一个简单的adapter,提供数据库Cursor到TextView的映射。
在实际开发过程中,除了TextView外,往往还需要依赖于数据库数据的其它的组件。
通过继承SimpleCursorAdapter,重写bindView(View view, Context context, Cursor cursor)来实现
public
View newView(Context context, Cursor cursor, ViewGroup parent)
07.
{
//找到布局和控件
08.
ViewHolder holder =
new
ViewHolder();
09.
LayoutInflater inflater = getLayoutInflater();
10.
View inflate = inflater.inflate(R.layout.listview_item,
null
);
11.
holder.item_tv_name = (TextView) inflate.findViewById(R.id.item_tv_name);
12.
holder.item_tv_phone = (TextView) inflate.findViewById(R.id.item_tv_phone);
13.
inflate.setTag(holder);
14.
return
inflate;
//返回的view传给bindView。
15.
}
16.
17.
@Override
18.
public
void
bindView(View view, Context context, Cursor cursor)
19.
{
//复用布局。www.it165.net
20.
// 把数据设置到界面上
21.
ViewHolder holder =(ViewHolder) view.getTag();
22.
String name = cursor.getString(cursor.getColumnIndex(
"name"
));
23.
String phone = cursor.getString(cursor.getColumnIndex(
"phone"
));
24.
holder.item_tv_name.setText(name);
25.
holder.item_tv_phone.setText(phone);
26.
}
相关文章推荐
- 开始iOS 7中自动布局教程
- android自定义keystore操作
- zhphp framework (十八) session 抽象接口
- 内核对象
- 关于html中的<div>框
- git常用命令总结
- My安装Eclipse三种方法插件
- 用CocoaPods做iOS程序的依赖管理
- 批处理文件的@echo off是什么意思?
- C#发送Email邮件三种方法的总结
- Java 之 文件读写及性能比较总结
- Android自定义View的实现方法
- Java实现输入
- SpringMVC中使用Interceptor拦截器
- 学习笔记20151211— 4000 —AXI4 STREAM DATA FIFO
- Linux 中直接 I/O 机制的介绍
- Sql Server中的日期与时间函数
- Python模板库Mako的语法
- 汇编指令详解
- IOS开发 文件下载 文件预览