Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to use CursorJoiner / MatrixCursor / MergeCursor?

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.

like image 447
CL22 Avatar asked Apr 18 '11 10:04

CL22


1 Answers

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 simple SQL JOIN.

MatrixCursor allows you to build something that implements the Cursor 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 a Cursor interface, overriding the methods that are necessary.

like image 140
CommonsWare Avatar answered Oct 20 '22 06:10

CommonsWare