Note that there are some explanatory texts on larger screens.

plurals
  1. POContactsContract and performance
    text
    copied!<p>I want to put into a listview all contact number. Some contacts have more than one phone number and I want to display a list this :</p> <pre><code>Pippo Number : +393934578987 Pippo Number : +394578952364 Topolino Number : +45124578972 Minnie Number : +39454545445b Minnie Number : +39457879758 etc </code></pre> <p>I used a SimpleAdapter with List and Maps but the performance was poor...than I decided to use the SimpleCursorAdapter and for to access the table ContactsContract and ContactsContract.CommonDataKinds.Phone a CursorJoiner with this code</p> <pre><code>Cursor cursor = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, ContactsContract.Contacts.HAS_PHONE_NUMBER + "=1", null, null); Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,null,ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = " + Contacts._ID, null, null); String[] cursor_join = new String[]{ Contacts._ID, ContactsContract.Contacts.DISPLAY_NAME, ContactsContract.CommonDataKinds.Phone.NUMBER }; MatrixCursor matrix_cursor = new MatrixCursor(cursor_join); CursorJoiner cursor_j = new CursorJoiner(cursor, new String[]{Contacts._ID}, phones, new String[]{ContactsContract.CommonDataKinds.Phone.CONTACT_ID}); for (CursorJoiner.Result joinerResult : cursor_j) { String[] values; switch (joinerResult) { case LEFT: // handle case where a row in cursorA is unique values = new String[]{ cursor.getString(cursor.getColumnIndex(Contacts._ID)), cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)), phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)) }; matrix_cursor.addRow(values); break; case RIGHT: // handle case where a row in cursorB is unique break; case BOTH: // handle case where a row with the same key is in both cursors values = new String[]{ cursor.getString(cursor.getColumnIndex(Contacts._ID)), cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)), phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)) }; matrix_cursor.addRow(values); break; } } while(matrix_cursor.moveToNext()){ contactId = matrix_cursor.getInt(matrix_cursor.getColumnIndex(Contacts._ID)); String name = matrix_cursor.getString(matrix_cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)); String num = matrix_cursor.getString(matrix_cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)); } </code></pre> <p>but it does not work </p> <p>someone tell me why?</p> <p>Thanks</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload