Android之CursorAdapter用法

本文详细介绍了CursorAdapter类,它是BaseAdapter的抽象子类,用于在Cursor数据源与ListView之间建立连接。文章强调了Cursor必须包含名为_id的列,并阐述了必须实现的新View和bindView方法的作用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

CursorAdapter
继承于BaseAdapter是个虚类,它为cursor和ListView提供了连接的桥梁。           
public abstract class  CursorAdapter  extends BaseAdapter
直接子类只有ResourceCursorAdapter
Class Overview
Adapter that exposes data from a Cursor to a ListView widget. 
The Cursor must include a column named "_id" or this class will not work.

注意cursor的必须要有个命名为"
_id"的列。比如Contacts._ID就为"_id"
必须实现以下函数

abstract View        newView(Context  context, Cursor  cursor, ViewGroup  parent)
    Makes a new view to hold the data pointed to by cursor(生成一个新的视图来保存光标指向的数据).
abstract void        bindView(View  view, Context  context, Cursor  cursor)
    Bind an existing view to the data pointed to by cursor(绑定光标指向的数据到现有的视图中)
注意
newView该函数第一次回调用后,如果数据增加后也会再调用,但是重绘是不会调用的。
数据增加后,回调用该函数来生成与新增数据相对应的view。
bindView函数第一次回调用后,如果数据更新也会再调用,但重绘会再次调用的。
【总的来说应该是在调用bindView如果发现view为空会先调用newView来生成view】
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值