public static ContactListAdapter createContactListAdapter(Context context,String defaultValue){
  ContentResolver content=context.getContentResolver();
  Cursor cursor=null;
  try {
    cursor=content.query(Phone.CONTENT_URI,PROJECTION_PHONE,WHERE_CLAUSE_PHONE,null,null);
    if (cursor == null) {
      throw new SQLException("Query failed!");
    }
    Set<ContactId> treatedNumbers=new HashSet<>();
    MatrixCursor matrix=new MatrixCursor(PROJECTION_PHONE);
    if (defaultValue != null) {
      matrix.addRow(new Object[]{-1,defaultValue,"",-1,-1});
    }
    int columnIdxId=cursor.getColumnIndexOrThrow(Phone._ID);
    int columIdxLabel=cursor.getColumnIndexOrThrow(Phone.LABEL);
    int columnIdxType=cursor.getColumnIndexOrThrow(Phone.TYPE);
    int columnIdxContactId=cursor.getColumnIndexOrThrow(Phone.CONTACT_ID);
    int columnIdxNumber=cursor.getColumnIndexOrThrow(Phone.NUMBER);
    while (cursor.moveToNext()) {
      String phoneNumber=cursor.getString(columnIdxNumber);
      if (!ContactUtil.isValidContact(phoneNumber)) {
        continue;
      }
      ContactId contact=ContactUtil.formatContact(phoneNumber);
      if (!treatedNumbers.contains(contact)) {
        matrix.addRow(new Object[]{cursor.getLong(columnIdxId),contact.toString(),cursor.getString(columIdxLabel),cursor.getInt(columnIdxType),cursor.getLong(columnIdxContactId)});
        treatedNumbers.add(contact);
      }
    }
    return new ContactListAdapter(context,matrix);
  }
  finally {
    if (cursor != null) {
      cursor.close();
    }
  }
}

public static ContactListAdapter createContactListAdapter ( Context context , String defaultValue ) { ContentResolver content = context . getContentResolver ( ) ; Cursor cursor = null ; try { cursor = content . query ( Phone . CONTENT_URI , PROJECTION_PHONE , WHERE_CLAUSE_PHONE , null , null ) ; if ( cursor == null ) { throw new SQLException ( "Query failed!" ) ; } Set < ContactId > treatedNumbers = new HashSet < > ( ) ; MatrixCursor matrix = new MatrixCursor ( PROJECTION_PHONE ) ; if ( defaultValue != null ) { matrix . addRow ( new Object [ ] { - 1 , defaultValue , "" , - 1 , - 1 } ) ; } int columnIdxId = cursor . getColumnIndexOrThrow ( Phone . _ID ) ; int columIdxLabel = cursor . getColumnIndexOrThrow ( Phone . LABEL ) ; int columnIdxType = cursor . getColumnIndexOrThrow ( Phone . TYPE ) ; int columnIdxContactId = cursor . getColumnIndexOrThrow ( Phone . CONTACT_ID ) ; int columnIdxNumber = cursor . getColumnIndexOrThrow ( Phone . NUMBER ) ; while ( cursor . moveToNext ( ) ) { String phoneNumber = cursor . getString ( columnIdxNumber ) ; if ( ! ContactUtil . isValidContact ( phoneNumber ) ) { continue ; } ContactId contact = ContactUtil . formatContact ( phoneNumber ) ; if ( ! treatedNumbers . contains ( contact ) ) { matrix . addRow ( new Object [ ] { cursor . getLong ( columnIdxId ) , contact . toString ( ) , cursor . getString ( columIdxLabel ) , cursor . getInt ( columnIdxType ) , cursor . getLong ( columnIdxContactId ) } ) ; treatedNumbers . add ( contact ) ; } } return new ContactListAdapter ( context , matrix ) ; } finally { if ( cursor != null ) { cursor . close ( ) ; } } }
create a contact selector based on the native address book . this selector adds a default value to allow no contact selection
