Hello Developers
I am trying to create the functionality of displaying a contact list and allow the user to select one of their contacts. I am using some code from the ApiDemos sample program, where I can create a listview activity and display the contact name and addresses. I can do this just by passing the names, not the data itself. I also need to pass the phone number, but there is only two slots for data on the listview layout.
My question, can anyone suggest a way to create a listview with contacts and attach the contact data to the view item?
I've looked in the code of the ApiDemos and it looks like they use a Map collection and call back to the Map by the position of the clicked object, but how would I manipulate a contact's name, formatted address and phone number, and also how would I store that correctly in the Map?
This is my code such far:
I hope that makes sense.
Thanks Much
-Adam
I am trying to create the functionality of displaying a contact list and allow the user to select one of their contacts. I am using some code from the ApiDemos sample program, where I can create a listview activity and display the contact name and addresses. I can do this just by passing the names, not the data itself. I also need to pass the phone number, but there is only two slots for data on the listview layout.
My question, can anyone suggest a way to create a listview with contacts and attach the contact data to the view item?
I've looked in the code of the ApiDemos and it looks like they use a Map collection and call back to the Map by the position of the clicked object, but how would I manipulate a contact's name, formatted address and phone number, and also how would I store that correctly in the Map?
This is my code such far:
Code:
[/FONT][/COLOR]
[COLOR=#646464][FONT=Verdana]//Listactivity on create[/FONT][/COLOR]
[COLOR=#646464][FONT=Verdana]@Override[/FONT][/COLOR]
[B][COLOR=#7f0055][FONT=Verdana]protected[/FONT][/COLOR][/B][B][COLOR=#7f0055][FONT=Verdana]void[/FONT][/COLOR][/B][COLOR=black][FONT=Verdana] onCreate(Bundle savedInstanceState) {[/FONT][/COLOR]
[B][COLOR=#7f0055][FONT=Verdana]super[/FONT][/COLOR][/B][COLOR=black][FONT=Verdana].onCreate(savedInstanceState);[/FONT][/COLOR]
[COLOR=#3f7f5f][FONT=Verdana]// Get a cursor with all phones[/FONT][/COLOR]
[COLOR=black][FONT=Verdana]Cursor c = getContentResolver().query(ContactsContract.CommonDataKinds.StructuredPostal.[/FONT][/COLOR][I][COLOR=#0000c0][FONT=Verdana]CONTENT_URI[/FONT][/COLOR][/I][COLOR=black][FONT=Verdana],[/FONT][/COLOR][B][COLOR=#7f0055][FONT=Verdana]null[/FONT][/COLOR][/B][COLOR=black][FONT=Verdana], [/FONT][/COLOR][B][COLOR=#7f0055][FONT=Verdana]null[/FONT][/COLOR][/B][COLOR=black][FONT=Verdana], [/FONT][/COLOR][B][COLOR=#7f0055][FONT=Verdana]null[/FONT][/COLOR][/B][COLOR=black][FONT=Verdana], [/FONT][/COLOR][B][COLOR=#7f0055][FONT=Verdana]null[/FONT][/COLOR][/B][COLOR=black][FONT=Verdana]);[/FONT][/COLOR]
[COLOR=black][FONT=Verdana]startManagingCursor(c);[/FONT][/COLOR]
[COLOR=#3f7f5f][FONT=Verdana]// Map Cursor columns to views defined in simple_list_item_2.[U]xml[/U][/FONT][/COLOR]
[COLOR=black][FONT=Verdana]Log.[I]d[/I]([/FONT][/COLOR][I][COLOR=#0000c0][FONT=Verdana]TAG[/FONT][/COLOR][/I][COLOR=black][FONT=Verdana], [/FONT][/COLOR][COLOR=#2a00ff][FONT=Verdana]"Creating ListAdapter"[/FONT][/COLOR][COLOR=black][FONT=Verdana]);[/FONT][/COLOR]
[COLOR=black][FONT=Verdana]ListAdapter adapter = [/FONT][/COLOR][B][COLOR=#7f0055][FONT=Verdana]new[/FONT][/COLOR][/B][COLOR=black][FONT=Verdana] SimpleCursorAdapter([/FONT][/COLOR][B][COLOR=#7f0055][FONT=Verdana]this[/FONT][/COLOR][/B][COLOR=black][FONT=Verdana],[/FONT][/COLOR]
[COLOR=black][FONT=Verdana]android.R.layout.[/FONT][/COLOR][I][COLOR=#0000c0][FONT=Verdana]simple_list_item_2[/FONT][/COLOR][/I][COLOR=black][FONT=Verdana], c, [/FONT][/COLOR]
[B][COLOR=#7f0055][FONT=Verdana]new[/FONT][/COLOR][/B][COLOR=black][FONT=Verdana] String[] { ContactsContract.CommonDataKinds.StructuredPostal.[/FONT][/COLOR][I][COLOR=#0000c0][FONT=Verdana]DISPLAY_NAME[/FONT][/COLOR][/I][COLOR=black][FONT=Verdana], ContactsContract.CommonDataKinds.StructuredPostal.[/FONT][/COLOR][I][COLOR=#0000c0][FONT=Verdana]FORMATTED_ADDRESS[/FONT][/COLOR][/I][COLOR=black][FONT=Verdana]}, [/FONT][/COLOR]
[B][COLOR=#7f0055][FONT=Verdana]new[/FONT][/COLOR][/B][B][COLOR=#7f0055][FONT=Verdana]int[/FONT][/COLOR][/B][COLOR=black][FONT=Verdana][] { android.R.id.[/FONT][/COLOR][I][COLOR=#0000c0][FONT=Verdana]text1[/FONT][/COLOR][/I][COLOR=black][FONT=Verdana],android.R.id.[/FONT][/COLOR][I][COLOR=#0000c0][FONT=Verdana]text2[/FONT][/COLOR][/I][COLOR=black][FONT=Verdana]});[/FONT][/COLOR]
[COLOR=black][FONT=Verdana]Log.[I]d[/I]([/FONT][/COLOR][I][COLOR=#0000c0][FONT=Verdana]TAG[/FONT][/COLOR][/I][COLOR=black][FONT=Verdana], [/FONT][/COLOR][COLOR=#2a00ff][FONT=Verdana]"Setting ListAdapter"[/FONT][/COLOR][COLOR=black][FONT=Verdana]+c);[/FONT][/COLOR]
[COLOR=black][FONT=Verdana]setListAdapter(adapter);[/FONT][/COLOR]
[COLOR=black][FONT=Verdana]}[/FONT][/COLOR]
[COLOR=black][FONT=Verdana]
I hope that makes sense.
Thanks Much
-Adam