0
좋아요. 연락처 등으로 작업하는 법을 배웁니다. 나는 내 연락처를 ListView에 나열하고 싶습니다. 사용자 정의 어댑터 (생각하면, ListView 항목에 ImageViews, TextViews 등이있을 수 있습니다.) 내가 가지고있는 다음 코드로 어떻게 할 수 있습니까?ListView에 연락처 추가
Cursor cursor = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
while (cursor.moveToNext()) {
String contactId = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
String hasPhone = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));
if (Boolean.parseBoolean(hasPhone)) {
// You know have the number so now query it like this
Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = "+ contactId, null, null);
while (phones.moveToNext()) {
String phoneNumber = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
}
phones.close();
}
}
cursor.close();
나는 이것을했지만 응용 프로그램을 실행할 때 아무것도 표시되지 않습니다. http://chiggins.pastebin.com/Hi4X58KX – Chiggins
좀 더 자세히 설명해 주시겠습니까? logcat에 오류가 있습니까? 샘플을 실행 중입니까? –