A MatrixCursor is one way:
ContentResolver contentResolver = getContentResolver(); Cursor peopleCursor = contentResolver.query( Contacts.People.CONTENT_URI, new String[] {Contacts.People._ID, Contacts.People.DISPLAY_NAME}, null, null, Contacts.People._ID); Cursor siCursor = contentResolver.query( Contacts.ContactMethods.CONTENT_URI, new String[] {Contacts.ContactMethods.PERSON_ID, Contacts.ContactMethods.DATA}, "label=\"secret_identity\"", null, Contacts.ContactMethods.PERSON_ID); CursorJoiner joiner = new CursorJoiner( peopleCursor, new String[] {Contacts.People._ID}, siCursor, new String[] {Contacts.ContactMethods.PERSON_ID}); MatrixCursor cursor = new MatrixCursor( new String[] {"_id","name","secret_identity"},10); for (CursorJoiner.Result joinerResult : joiner) { switch (joinerResult) { case BOTH: // handle case where a row with the same key is in both cursors String id = peopleCursor.getString(0); String name = peopleCursor.getString(1); String secret_identity = sipCursor.getString(1); cursor.addRow(new String[] {id,name,secret_identity}); break; } } startManagingCursor(cursor); listAdapter = new SimpleCursorAdapter( this, R.layout.contacts, cursor, new String[] {"name"}, new int[] {R.id.row_name}); setListAdapter(listAdapter); } catch (Exception e) { e.printStackTrace(); // a little more finesse in exception handling may be called for here } On Jun 25, 12:24 pm, NTDYLF <notthedroidyourelooking...@gmail.com> wrote: > Hello all, I have two tables I want to (inner) join, Contacts.People > and Contacts.ContactMethods. The result will be displayed in a > ListActivity. After looking into this, it appears that I should use > CursorJoiner. So the code would look something like this: > > // 1) prepare cursors > Cursor peopleCursor = contentResolver.query( > Contacts.People.CONTENT_URI, > new String[] {Contacts.People._ID, > Contacts.People.DISPLAY_NAME}, > null, > null, > Contacts.People._ID); > > Cursor cmCursor = contentResolver.query( > Contacts.ContactMethods.CONTENT_URI, > new String[] > {Contacts.ContactMethods.PERSON_ID, > Contacts.ContactMethods.DATA}, > "label=\"secret identity\"", > null, > Contacts.ContactMethods.PERSON_ID); > > // 2) join them > CursorJoiner joiner = new CursorJoiner( > peopleCursor, > new String[] {Contacts.People._ID}, > cmCursor, > new String[] > {Contacts.ContactMethods.PERSON_ID}); > for (CursorJointer.Result joinerResult : joiner) { > switch (joinerResult) { > case BOTH: // handle case where a row with > the same key is > in both cursors > > // I think I'm supposed to do > something here > > break; > } > } > > // 3) Make a list adapter from a cursor > > So my question is, how to I make a new cursor from the first two? > Thanks in advance. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---