ContentResolver cr = getContentResolver();
Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,null, null, null, null);
View view=View.inflate(context, R.layout.main, null);
ListView list = (ListView)view. findViewById(android.R.id.list);
String[] columns = new String[{ContactsContract.Contacts.DISPLAY_NAME,ContactsContract.PhoneLookup.NUMBER};
int[] views = new int[] {R.id.contactName, R.id.contactID};
SimpleCursorAdapter adapter = new SimpleCursorAdapter(context,R.layout.text,cur,columns, views);
list.setAdapter(adapter);
答案 0 :(得分:2)
this is real example
public Cursor getAllContacts() {
Uri uri = ContactsContract.Contacts.CONTENT_URI;
String[] projection = new String[] {
ContactsContract.Contacts._ID,
ContactsContract.Contacts.LOOKUP_KEY,
ContactsContract.Contacts.DISPLAY_NAME,
ContactsContract.Contacts.DISPLAY_NAME_ALTERNATIVE
};
String selection = ContactsContract.Contacts.HAS_PHONE_NUMBER + " = '1'";
String[] selectionArgs = null;
String sortOrder = ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC";
return getContentResolver().query(uri, projection, selection, selectionArgs, sortOrder);
}