I would like to build a custom ListView of information from contacts in Android.
The Android docs layout a really simple example here: https://developer.android.com/training/contacts-provider/retrieve-names#Permissions
It grabs the display name from your contacts and shows it in the list view. The projection given to the CursorLoader is:
private val PROJECTION: Array<out String> = arrayOf(
ContactsContract.Contacts._ID,
ContactsContract.Contacts.LOOKUP_KEY,
ContactsContract.Contacts.DISPLAY_NAME
)
Then map to the simple cursor:
private val FROM_COLUMNS: Array<String> = arrayOf(
ContactsContract.Contacts.DISPLAY_NAME
)
I would like to also add an email address to the listview. Is this possible with a the SimpleCursorAdapter that the documentation uses?
I tried to change the projection to project the email address as well:
private val PROJECTION: Array<out String> = arrayOf(
ContactsContract.Contacts._ID,
ContactsContract.Contacts.LOOKUP_KEY,
ContactsContract.Contacts.DISPLAY_NAME,
ContactsContract.CommonDataKinds.Email.DISPLAY_NAME
)
However when I do that I get an exception:
java.lang.IllegalArgumentException: Invalid column data4
I realize that the mapping from contacts to email(s) is one to many. Is that my problem? Can I project the "Main" email address?