Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- try {
- 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, //left
- new String[] {Contacts.People._ID}, //left cols
- siCursor, //right
- new String[] {Contacts.ContactMethods.PERSON_ID}); //right cols
- MatrixCursor cursor = new MatrixCursor(
- new String[] {"_id","name","secret_identity"});
- for (CursorJoiner.Result joinerResult : joiner) {
- switch (joinerResult) {
- case LEFT: //do this when the left row is absolutely unique
- break;
- case BOTH: // handle case where any 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;
- case RIGHT:
- 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
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement