何时使用 CursorJoiner / MatrixCursor / MergeCursor?
我正在探索从两个或多个连接表中优雅地获取数据的不同方法。
我相信 MergeCursor
,(Android 开发人员指南)似乎暗示可以(例如)通过连接两个查询(或将视图单独添加为行等)来替换等效的SQL UNION
- 所以,这不是我想要的。
但我不知道 CursorJoiner
和 MatrixCursor
到底是做什么的,或者如何使用它们。我已经查看了它们的来源(像往常一样),这对我来说毫无意义!我发现它们的使用示例并没有清楚地解释所产生的效果是什么。我真的很感激对它们以及它们可能使用的上下文的详细描述。
I'm exploring different ways to get data elegantly from two or more joined tables.
I believe MergeCursor
, (Android Developer Guide) seems to imply that could (for example) replace an equivalent SQL UNION
by concatenating two queries (or adding views individually as rows, etc) - so, not what I want.
But I'm at a loss as to what exactly CursorJoiner
and MatrixCursor
are for, or how to use them. I've looked at the source for them and (as usual) it means nothing to me! The examples I've found of them in use didn't clearly explain what the resulting effect was. I would really appreciate a good description of them, and the context they might be used in.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如您所指出的,MergeCursor 旨在“垂直”连接两个数据集,添加更多行。
CursorJoiner 旨在“水平”连接两个数据集,添加更多列。您可以将其视为类似于实现简单的
SQL JOIN
。MatrixCursor
允许您构建一些从纯数据中实现Cursor
接口的东西,然后将其倒入二维数据模型中。AbstractCursor
允许您将自己的自定义数据集包装在Cursor
接口中,覆盖必要的方法。MergeCursor
, as you indicate, is designed to concatenate two data sets "vertically", adding more rows.CursorJoiner
is designed to concatenate two data sets "horizontally", adding more columns. You can think of this as akin to implementing a simpleSQL JOIN
.MatrixCursor
allows you to build something that implements theCursor
interface out of pure data, that you pour into a two-dimensional data model.AbstractCursor
allows you to wrap your own custom data set in aCursor
interface, overriding the methods that are necessary.关于MatrixCursor,这里有一个使用示例。
这将返回数据的解密版本(在本例中仅一列,但在完整版本中许多列都被加密)。
简而言之,它与使用普通游标没什么不同,只不过您在创建实例时定义了列。然后,您可以使用
addRow
方法添加行。With regard to MatrixCursor, here's an example use.
This returns a decrypted version of the data (in this case just one column, but in the full version a number of columns are encrypted).
In short it's little different to using a normal cursor, except you define the columns when you create an instance. You can then add rows with the
addRow
method.