首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >关于SimpleCursorTreeAdapter和getChildrenCursor()的帮助

关于SimpleCursorTreeAdapter和getChildrenCursor()的帮助
EN

Stack Overflow用户
提问于 2011-03-05 14:33:50
回答 3查看 2.1K关注 0票数 3

我有一个包含三列的sqlite数据库: id、日期和字符串。对于单个日期,可以有多个字符串与之关联,因此我有多个日期相同但字符串不同的行。

我想使用ExpandableListView来显示这些数据。我需要在SimpleCursorTreeAdapter中实现getChildrenCursor()以便将其用于此目的,但我不确定如何做到这一点。我看过this,我看到它使用managedQuery,但我没有内容提供商,所以我无法使用它。根据我的understand,getChildrenCursor()的目的是获得一个只包含可以放入子对象中的数据的游标,但是我不明白这个方法如何根据条目的日期来分隔条目,因为它只作为参数传递了一个游标。

EN

回答 3

Stack Overflow用户

发布于 2011-03-07 15:11:46

代码语言:javascript
复制
public class MyExpandableListAdapter extends SimpleCursorTreeAdapter {

    public MyExpandableListAdapter(Cursor cursor, Context context, int groupLayout,
            int childLayout, String[] groupFrom, int[] groupTo, String[] childrenFrom,
            int[] childrenTo) {
        super(context, cursor, groupLayout, groupFrom, groupTo, childLayout, childrenFrom,
                childrenTo);
    }

    @Override
    @SuppressWarnings("deprecation")
    protected Cursor getChildrenCursor(Cursor groupCursor) {
        // Given the group, we return a cursor for all the children within that group 
        // Return a cursor that points to this contact's phone numbers
        Uri.Builder builder = People.CONTENT_URI.buildUpon();
        ContentUris.appendId(builder, groupCursor.getLong(mGroupIdColumnIndex));
        builder.appendEncodedPath(People.Phones.CONTENT_DIRECTORY);
        Uri phoneNumbersUri = builder.build();
        // The returned Cursor MUST be managed by us, so we use Activity's helper
        // functionality to manage it for us.
        return managedQuery(phoneNumbersUri, mPhoneNumberProjection, null, null, null);
    }
}
票数 0
EN

Stack Overflow用户

发布于 2011-11-24 05:57:29

我知道已经晚了8个月了,但还是。

您可以在没有内容提供商的情况下创建光标。打开SQLite数据库并执行db.query(...) -这将为您创建一个游标。这与内容提供商创建光标的方式相同。

票数 0
EN

Stack Overflow用户

发布于 2014-07-09 06:58:34

不应使用managedQuery,因为它已在API11中折旧。

groupCursor对象可以用来表示get一个"_id“,用于查询它的子数据。"?“是来自组游标的ID列,它最有可能用作另一个表上的外键。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5202161

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档