No matter what I do, the following throws an error that one of the columns contained in the cursor_counterparty does not exist. When I checked the merge_cursor, I can find the column in there, here's my code, what am I doing wrong?
cursor_invoices = Invoices.getInvoicesCursor(counterparty.getId());
Cursor cursor_counterparty = Counterparties
.getCounterpartyCursor(counterparty.getId());
startManagingCursor(cursor_invoices);
startManagingCursor(cursor_counterparty);
/* Joins cursors akin to doing an SQL join */
MergeCursor merge_cursor = new MergeCursor(new Cursor[] {
cursor_invoices, cursor_counterparty });
merge_cursor.moveToFirst();
int[] listview_columns = new int[] { R.id.textview_invoice_number,
R.id.textview_counterparty_name, R.id.textview_amount,
R.id.textview_account_name, R.id.textview_invoice_date,
R.id.textview_date_paid };
String[] listview_fields = new String[] { App.INVOICENUMBER,
App.COUNTERPARTYNAME, counterparty_amount_field,
App.ACCOUNTNAME, App.INVOICEDATE, App.DATEPAID };
SimpleCursorAdapter cursor_adapter_invoices = new SimpleCursorAdapter(
this, R.layout.listview_invoice_item, merge_cursor,
listview_fields, listview_columns);
The error I get is:
java.lang.IllegalArgumentException: column 'counterparty_name' does not exist
When I debug the App, I can see 'counterparty_name' as a column in one of the cursors in the merge_cursor.
Any help would be great, thanks!
Are you wanting to join the cursors vertically (adding rows) or horizontally (adding columns)?
This is theory, as I haven't peeked at the code, but it makes sense to me...
MergeCursor concatenates cursors vertically (fact), one after another. So for part of the cursor you have one set of columns and for the other you have a different set of columns (supposition).
Your adapter is trying to find a column that doesn't exist in one portion or the other for the row being displayed.
If you changed to a CursorJoiner, which concatenates the columns, I think it would work more like you expect, although how you would line up the rows appropriately I don't know.
A good explanation here
EDIT
I see you use the same ID to fetch each cursor, so my concern about lining them up is irrelevant. I think you do want CursorJoiner rather than MergeCursor.