私のアプリでは、リストビューに連絡先をリストしています。連絡先の数は1000以上です。私は連絡先を取得します
cr.query(...) であるContentResolver クエリを使用して、配列リストに値を格納します。
その後、配列リストを setListAdapter(...) にロードします。すべての連絡先を表示するには
アプリは1分近くかかるので、非同期タスクを使用しますが、非同期タスクを使用しても大きな違いはありません。
2 ~ 4 秒以内にすべての連絡先を表示する必要があります。2〜4秒以内にロードされるAndroidシミュレーターのデフォルトの連絡先アプリケーションをチェックインします。 私は過ごしました
久しぶりのグーグル。しかし、私は役立つ解決策を得ることができませんでした。リストビューで連絡先の読み込みを高速化する方法を教えてください。私を助けてください。
私のコーディングサンプル:
private ArrayList<ContactListEntry> loadContactListInternal(String searchString) {
ArrayList<ContactListEntry> contactList = new ArrayList<ContactListEntry>();
ContentResolver cr = getContentResolver();
Cursor cur = null;
String[] projection = new String[] {BaseColumns._ID,ContactsContract.Contacts.DISPLAY_NAME,ContactsContract.Contacts.PHOTO_ID};
....
cur=cr.query(ContactsContract.Contacts.CONTENT_URI, projection, selection, null, ContactsContract.Contacts.DISPLAY_NAME + " ASC");
while (cur.moveToNext()) {
int id = Integer.parseInt(cur.getString(0));
....
if (input !=null)
photo = BitmapFactory.decodeStream(input);
....
ArrayList<ContactListEntry.PhoneEntry> phoneEntries = new ArrayList<ContactListEntry.PhoneEntry>();
String[] projection1 = new String[] {ContactsContract.CommonDataKinds.Phone.NUMBER,ContactsContract.CommonDataKinds.Phone.TYPE};
Cursor pcur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,projection1, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?", new String[] { String.valueOf(id) }, null);
while (pcur.moveToNext()) {
...
}
pcur.close();
ContactListEntry entry = new ContactListEntry(id, name, photo, phoneEntries);
contactList.add(entry);
}
cur.close();
return contactList;
}
.....
in another class
private void selectionUpdated() {
....
setListAdapter(new SelectedArrayAdapter(this, app.selectedContacts));
...
}