I have what I assumed was a straight forward issue, but after a thorough search I can find no solution:
I have two data sources with two distinct data types: apples and oranges. The only column in common is “datePicked”. I want to query the separate databases and then display both apples and oranges in the same list ordered and grouped by “datePicked”.
I see some suggestions to use MergeAdapter. However, unless I am missing something, MergeAdapter simply concatenates two Adapters, it doesn’t really merge them. Likewise, I have seen suggestions to use MatrixCursor or MergeCursor to create a single unified cursor and then creating an adapter for that. Neither seem a good solution. MergeCursor appears only to concatenate the cursors, while MatrixCursor appears to require that I iterate through both datasets start to finish building a cursor row by row. Even if these were acceptable solutions, I still have the problem that different schema require different layout on the screen. How would I inflate different layout based on underlying data type?
So I am stumped, and would appreciate any help. Is there a true merge adapter that will interleave the data rather than just concatenate it? If not, is there a way to create an Adapter that conditionally maps and inflates a layout based on some business logic done to the specific row being pointed at by the cursor?
Sorry if I am missing something obvious.
Thanks,
To answer my own question, it appears that building a Matrix cursor with a merge-sorted-list type algorithm stepping through both cursors, and then conditionally inflating a row layout by overriding the newView() method with an if statement is the only workable solution. I will post the code for anyone who is interested once I’ve worked out the details.