CursorTreeAdapter自定义Cursor

CursorTreeAdapter

其实这类是一个超级坑人的类:

1,API文档中没有详细声明使用方法

2,官方说明必须包含有一个列为_id,并没有说明这个_id是用来干吗

3,如果你自己写数据库来操纵,会有大把问题出现


使用过程中遇到一些问题:

1,开发数据列表时,所有数据存储在SQLITE中,而每个部门有很多成员,总是重复出现

2,在使用自定义ContentProvider时,uri指定出现一些莫名问题

3,当你使用SQLite语句来控制ContentProvider时,扩展开不来子View


最后解决办法:

借用API与SQLite,直接操控Group与Children View,子View的指定由CursorTreeAdapter来操作,这样

就两者兼得了,还有就是_id是用来指定一组数据中存储成员id,当你自己来操控数据时,可以随意定义

但是数据库内的分组id必须一致

类声明:

An adapter that exposes data from a series of Cursors to an ExpandableListView widget. The top-level Cursor (that is given in the constructor) 

exposes the groups, while subsequent Cursors returned from getChildrenCursor(Cursor)expose children within a particular group. 

The Cursors must include a column named "_id" or thisclass will not work.


继承后需要重写的方法:

1,protected void bindChildView(View view, Context context, Cursor cursor, boolean isExpanded)

2,protected void bindGroupView(View view, Context context, Cursor cursor, boolean isExpanded)

3,protected Cursor getChildrenCursor(Cursor groupCursor)

4,protected View newChildView(Context context, Cursor cursor, boolean isExpanded, ViewGroup parent)

5,protected View newGroupView(Context context, Cursor cursor, boolean isExpanded, ViewGroup parent)


其中,方法作用:

方法1与方法4是一对,方法1用于绑定数据到方法4中已经指定好的View

方法2与方法5是一对,方法2用于绑定数据到方法5中已经指定好的View

方法3是在伸缩开的ListView中指定要查询的子Cursor,类如:

你查询自己数据库中一个指定的部门,就可以在方法3中返回查询好的指针


在方法3中,必须指定一个列名为_id的列,否则无法进行查询



有讨论可与本人交谈QQ:563611060

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值