I'm creating an app that needs to display the phone contacts with its photo, name and number. I've created a ListView and can show contacts and numbers with a generic photo, but I can't show contat's picture. This is my code:
Cursor cursor = getContacts();
String[] fields = new String[] {Contacts.DISPLAY_NAME, Phone.NUMBER};
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.contact_entry, cursor,
fields, new int[] {R.id.contactEntryText, R.id.contactEntryNumber});
mContactList.setAdapter(adapter);
private Cursor getContacts()
// Run query
Uri uri = Phone.CONTENT_URI;
String[] projection = new String[] {
Contacts._ID,
Contacts.DISPLAY_NAME,
Phone.NUMBER,
Contacts.PHOTO_ID
};
//String selection = Contacts.HAS_PHONE_NUMBER + "='1'";
String selection = null;
String[] selectionArgs = null;
String sortOrder = Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC";
return managedQuery(uri, projection, selection, selectionArgs, sortOrder);
}
How can I attach the contact's picture in the SimpleCursorAdapter? Is there another?
Thank you very much.
I figured it out. If someone had the same problem, this is how i did it:
In an activity that extends ListActivity:
In a custom adapter:
I know it is a very old question but so is the answer as few things in this solution have now been deprecated. As the question showed up in searches while I was looking for similar solution, I though I will add my two cents here...
I have created a simple contacts list with their names and photos from
ContactsContract
. Please check my answer at... https://stackoverflow.com/a/37710199/1209544