有关 SimpleCursorTreeAdapter 和 getChildrenCursor() 的帮助
我有一个包含三列的 sqlite 数据库:id、日期和字符串。对于单个日期,可以有多个与之关联的字符串,因此我有多行具有相同的日期,只是具有不同的字符串。
我想使用 ExpandableListView 来显示这些数据。我需要在 SimpleCursorTreeAdapter 中实现 getChildrenCursor() 才能将其用于此目的,但我不确定如何执行此操作。我看过这个,我发现它使用 ManagedQuery,但我没有内容提供程序,因此无法使用它。从我的 明白,getChildrenCursor()的目的是获取一个只包含可以放入子项的数据的游标,但我看不出这个方法如何根据日期分隔条目,因为它只传递了一个 Cursor 作为参数。
I have an sqlite database with three columns: id, a date and a string. For a single date there can be multiple strings associated with it, so I have multiple rows with the same date just with different strings.
I want to use an ExpandableListView to show this data. I need to implement getChildrenCursor() in SimpleCursorTreeAdapter in order to use it for this purpose, but I am not sure how to do so. I have looked at this and I see that it uses managedQuery, but I do not have a content provider so I cannot use it. From what I understand, the purpose of getChildrenCursor() is to get a cursor with only the data that can be put in a child, but I can't see how this method can separate the entries according to their dates, since it's only passed a Cursor as a parameter.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我知道已经晚了 8 个月,但仍然如此。
您可以在没有内容提供者的情况下创建光标。打开 SQLite 数据库并执行 db.query(...) - 这将为您创建一个游标。这与内容提供商创建光标的方式相同。
I know it's 8 months too late, but still.
You can create cursor without a content provider. Open the SQLite database and do db.query(...) - this will create a cursor for you. It's the same way content providers create cursors.
如果您不想使用 ContentProvider,请尝试在 AsyncTask 中运行查询。然后使用onPostExecute内部的changeCursor方法来换出Cursor。
不应使用 ManagedQuery,因为它已在 API 11 中被弃用。
groupCursor 对象可用于表示获取“_id”以用于查询其子数据。例如 SELECT * FROM 'TABLE' WHERE ID = ?。这 ”?”是组游标中的 ID 列,很可能将用作另一个表上的外键。如果您仍然感到困惑,请尝试在谷歌上搜索“数据库规范化”。
If you do not want to use a ContentProvider try running your query in an AsyncTask. Then use the changeCursor method inside onPostExecute to swap out the Cursor.
managedQuery should not be used as it has been depreciated in API 11.
The groupCursor object can be used to say get an "_id" for use in querying for its child data. like SELECT * FROM 'TABLE' WHERE ID = ?. the "?" being an ID column from the group cursor, which is most likely going to be used as a foreign key on another table. If you're still confused try searching for "Database Normalization" on google.