我已經制作了一個自定義列表,在該列表中,我獲取了所有電話簿聯繫人並使用自定義視圖在我自己的列表中顯示它們。我將所有聯繫人(包括聯繫人ID)保存在一個數組列表中。當我點擊一個列表時,我希望它以默認的Android方式打開該聯繫人的所有細節。請有人告訴我這是否可能。獲取電話簿聯繫人自定義列表中的詳細信息頁面android
我的代碼如下保存在我自己的列表中的聯繫人:
arraylist = new ArrayList<PhoneBookUserEntity>();
Cursor cursor = getContentResolver().query(
ContactsContract.Contacts.CONTENT_URI, null, null, null, Phone.DISPLAY_NAME + " ASC");
if (cursor.getCount() > 0)
{
while (cursor.moveToNext())
{
PhoneBookUserEntity user = new PhoneBookUserEntity();
// Pick out the ID, and the Display name of the
// contact from the current row of the cursor
user.setId(cursor.getString(cursor.getColumnIndex(BaseColumns._ID)));
user.setPhoneBookName(cursor.getString(cursor.getColumnIndex(
ContactsContract.Contacts.DISPLAY_NAME)));
String hasPhone = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));
// if (Boolean.parseBoolean(hasPhone)) {
Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = "+ user.getId(), null, null);
while (phones.moveToNext()) {
user.sePhoneNumber(phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)));
}
phones.close();
//}
// user.sePhoneNumber(cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)));
Cursor emails = getContentResolver().query(ContactsContract.CommonDataKinds.Email.CONTENT_URI, null, ContactsContract.CommonDataKinds.Email.CONTACT_ID + " = " + user.getId(), null, null);
while (emails.moveToNext()) {
// This would allow you get several email addresses
user.setEmailAddress(emails.getString(emails.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA)));
}
emails.close();
user.setImageURI(getPhotoUri(user.getId()));
arraylist.add(user);
// Do something with the values you have,
// such as print them out or add to a list
//System.out.println("Current contact on this iteration is : " + name);
// This is where we query for Emails, Addresses etc
// Add snippets below into here, depending on what you need
}
}
cursor.close();
打開聯繫人卡片BTW,你可以使用聯繫人選擇器來執行類似的功能。退房http://tutorials-android.blogspot.in/2011/11/how-to-call-android-contacts-list.html – Soham 2012-03-06 12:58:32
我有我的自定義列表中的聯繫人。我想打開默認視圖,當有人點擊一個聯繫人,他們會顯示聯繫人的詳細信息。 – SoH 2012-03-06 13:02:09