继承SimpleCursorAdapter定制Adapter
来源:互联网 发布:票乎为什么停止运营 编辑:程序博客网 时间:2024/06/05 22:46
以前对newview 和bindview的理解不是很深,今天特意研究研究。
- 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.
- 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.
}
0 0
- 继承SimpleCursorAdapter定制Adapter
- android 部分原生Adapter简介之SimpleCursorAdapter
- Android中Adapter之SimpleCursorAdapter使用
- Android中Adapter之SimpleCursorAdapter使用
- 与数据库打交道的Adapter----SimpleCursorAdapter
- Android-Adapter实现方法(ArrayAdapter,SimpleAdapter,SimpleCursorAdapter)
- Adapter基础讲解-SimpleCursorAdapter使用示例
- 通过定制SimpleCursorAdapter来实现ListView
- SimpleCursorAdapter
- SimpleCursorAdapter
- Android学习之Adapter:SimpleAdapter,SimpleCursorAdapter,ArrayAdapter(数据库 列表)
- [Android] Adapter:SimpleAdapter SimpleCursorAdapter ArrayAdapter 与ListView的用法
- Adapter的继承关系
- android adapter继承结构
- Adapter 继承关系图
- Adapter的继承结构
- Adapter的继承结构
- Adapter的继承结构
- fragment之基本使用
- zhphp framework (十八) session 抽象接口
- ajax加载的元素无法绑定事件问题解决
- Linux+PHP(5.4+)+MEMCACHE
- android自定义keystore操作
- 继承SimpleCursorAdapter定制Adapter
- HELLO WORLD
- Android内存优化之一:MAT使用入门
- Android 5.1编译大于2G的OTA包是会出 Android OverflowError: size does not fit in an int或者would require ZIP64 ex
- 从源码的角度分析Thread、Looper、MessageQueue、Handler的关系
- zhphp framework (十八) php 验证类
- Objective-C总Runtime的那点事儿
- 删除文件
- 接口回调机制