我正在为android创建一个联系人应用程序,我已经成功创建了联系人的列表视图,还检索了联系人图像(对于那些有图像的联系人)和没有任何图像的联系人显示没有任何图像没有任何图像显示。我需要使用默认的接触轮廓图像显示没有任何图像的联系人。这是代码
private void populateContactList() {
// TODO Auto-generated method stub
// Build adapter with contact entries
Cursor cursor = getContacts();
String[] fields = new String[] { ContactsContract.Data.DISPLAY_NAME,
ContactsContract.Data.PHOTO_THUMBNAIL_URI };
adapter = new SimpleCursorAdapter(this, R.layout.contactentrylayout,
cursor, fields, new int[] { R.id.contactEntryText,
R.id.contactimageentry });
mContactList.setAdapter(adapter);
}
@SuppressWarnings("deprecation")
private Cursor getContacts() {
// TODO Auto-generated method stub
// Run query
Uri uri = ContactsContract.Contacts.CONTENT_URI;
String[] projection = new String[] { ContactsContract.Contacts._ID,
ContactsContract.Contacts.DISPLAY_NAME,
ContactsContract.Data.PHOTO_THUMBNAIL_URI };
// String selection = ContactsContract.Contacts.IN_VISIBLE_GROUP +
// " = '"
// + (mShowInvisible ? "0" : "1") + "'";
String selection = ContactsContract.Contacts.DISPLAY_NAME
+ " LIKE ? OR "
+ ContactsContract.Contacts.DISPLAY_NAME_ALTERNATIVE
+ " LIKE ?";
String[] selectionArgs = { etquery.getText().toString() + "%",
etquery.getText().toString() + "%" };
String sortOrder = ContactsContract.Contacts.DISPLAY_NAME
+ " COLLATE LOCALIZED ASC";
return managedQuery(uri, projection, selection, selectionArgs,
sortOrder);
}