전화상의 모든 연락처의 이름과 전화 번호로 목록보기를 만들어야합니다. 코드가 작동하지만 사용자가 많은 연락처를 가지고있을 때 너무 많은 시간이 걸립니다. 개선 할 수있는 방법이 있습니까?개선 시간 전화 번호 받기
public List<Contact> fetchContacts() {
String phoneNumber = null;
String email = null;
Uri CONTENT_URI = ContactsContract.Contacts.CONTENT_URI;
String _ID = ContactsContract.Contacts._ID;
String DISPLAY_NAME = ContactsContract.Contacts.DISPLAY_NAME;
String HAS_PHONE_NUMBER = ContactsContract.Contacts.HAS_PHONE_NUMBER;
Uri PhoneCONTENT_URI = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
String Phone_CONTACT_ID = ContactsContract.CommonDataKinds.Phone.CONTACT_ID;
String NUMBER = ContactsContract.CommonDataKinds.Phone.NUMBER;
ContentResolver contentResolver = getContentResolver();
Cursor cursor = getContentResolver().query(CONTENT_URI, null, null, null, DISPLAY_NAME + " ASC");
List<Contact> contactList = new ArrayList<Contact>();
// Loop for every contact in the phone
if (cursor.getCount() > 0) {
while (cursor.moveToNext()) {
String contact_id = cursor.getString(cursor.getColumnIndex(_ID));
String name = cursor.getString(cursor.getColumnIndex(DISPLAY_NAME));
int hasPhoneNumber = Integer.parseInt(cursor.getString(cursor.getColumnIndex(HAS_PHONE_NUMBER)));
if (hasPhoneNumber > 0) {
Cursor phoneCursor = contentResolver.query(PhoneCONTENT_URI, null, Phone_CONTACT_ID + " = ?", new String[]{contact_id}, null);
phoneCursor.moveToNext();
phoneNumber = phoneCursor.getString(phoneCursor.getColumnIndex(NUMBER));
phoneCursor.close();
Contact contacto = new Contact();
contacto.name = name;
contacto.phone = phoneNumber;
contacto.id = contact_id;
contactList.add(contacto);
}
}
}
return contactList;
}
이 질문의 제목에 Google 검색을 넣지 마십시오 목록보기에 재활용 빨리보기 위해 ViewHolder 패턴을 찾아 넣어 :에서 newView .findViewById (...)
팁이 모두 수행해야합니다 * 당신이 기대하는 실제 검색 결과 귀하의 질문 제목에 ur Google 검색 *. –