Advertisement
moonlightcheese

Untitled

Jul 20th, 2011
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.58 KB | None | 0 0
  1. try {
  2.     ContentResolver contentResolver = getContentResolver();
  3.     Cursor peopleCursor = contentResolver.query(
  4.         Contacts.People.CONTENT_URI,
  5.         new String[] {Contacts.People._ID, Contacts.People.DISPLAY_NAME},
  6.         null,
  7.         null,
  8.         Contacts.People._ID);
  9.     Cursor siCursor = contentResolver.query(
  10.         Contacts.ContactMethods.CONTENT_URI,
  11.         new String[] {Contacts.ContactMethods.PERSON_ID, Contacts.ContactMethods.DATA},
  12.         "label=\"secret_identity\"",
  13.         null,
  14.         Contacts.ContactMethods.PERSON_ID);
  15.     CursorJoiner joiner = new CursorJoiner(
  16.         peopleCursor,   //left
  17.         new String[] {Contacts.People._ID}, //left cols
  18.         siCursor,   //right
  19.         new String[] {Contacts.ContactMethods.PERSON_ID});  //right cols
  20.  
  21.     MatrixCursor cursor = new MatrixCursor(
  22.         new String[] {"_id","name","secret_identity"});
  23.  
  24.     for (CursorJoiner.Result joinerResult : joiner) {
  25.         switch (joinerResult) {
  26.             case LEFT: //do this when the left row is absolutely unique
  27.                
  28.                 break;
  29.             case BOTH: // handle case where any row with the same key is in both cursors
  30.                 String id = peopleCursor.getString(0);
  31.                 String name = peopleCursor.getString(1);
  32.                 String secret_identity = sipCursor.getString(1);
  33.                 cursor.addRow(new String[] {id,name,secret_identity});
  34.                 break;
  35.             case RIGHT:
  36.                 break;
  37.         }
  38.     }
  39.  
  40.     startManagingCursor(cursor);
  41.     listAdapter = new SimpleCursorAdapter(
  42.         this,
  43.         R.layout.contacts,
  44.         cursor,
  45.         new String[] {"name"},
  46.         new int[] {R.id.row_name});
  47.     setListAdapter(listAdapter);
  48. } catch (Exception e) {
  49.     e.printStackTrace(); // a little more finesse in exception handling may be called for here
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement