java - How to open a contact detail card in listView with contact names with onListItemClick in Android? -
i have contact app displays names of contact, arrayadapter. works fine want to open native contact app details of contact whenever click on name.
thank in advance!
public class mainactivity extends listactivity { private customadapter customadapter; list<string> contacts = new arraylist<string>(); @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); listview lv = (listview) findviewbyid(android.r.id.list); customadapter = new customadapter(this); lv.setadapter(customadapter); } @override protected void onresume() { super.onresume(); log.d("tag","onresume"); loadapps(); } public void loadapps(){ //cursor cursor = getcontentresolver().query(contactscontract.commondatakinds.phone.content_uri, null, null, null, null); cursor cursor; contentresolver contentresolver = getcontentresolver(); cursor = contentresolver.query(contactscontract.contacts.content_uri,null, contactscontract.contacts.has_phone_number + " = 1", null, "upper(" + contactscontract.contacts.display_name + ") asc"); customadapter.clear(); if (cursor.getcount() > 0) { cursor.movetofirst(); { string name = cursor.getstring(cursor.getcolumnindex(contactscontract.contacts.display_name)); contacts.add(name); } while (cursor.movetonext()); } cursor.close(); (string names : contacts) { appinfoitem appinfoitem = new appinfoitem(); appinfoitem.name = names; customadapter.add(appinfoitem); } } @override protected void onlistitemclick(listview l, view v, int position, long id) { super.onlistitemclick(l, v, position, id); intent intent = new intent(intent.action_view, uri.parse("content://contacts/people/")); if (intent != null) { startactivity(intent); } } }
customarrayadapter.class
public class customadapter extends arrayadapter<string> { layoutinflater layoutinflater; public customadapter(context context) { super(context, 0); layoutinflater = (layoutinflater) context.getsystemservice(context.layout_inflater_service); } @override public view getview(int position, view convertview, viewgroup parent) { // create cell , populate data of array if (convertview == null) convertview = layoutinflater.inflate(android.r.layout.simple_list_item_1, parent, false); appinfoitem item = (appinfoitem) getitem(position); //string name = names[position]; textview textview = (textview) convertview.findviewbyid(android.r.id.text1); textview.settext(item.name); return convertview; } }
appinfoitem.class
public class appinfoitem { string name; string id; }
i think need use intent
action_view action , intent data set contact's uri of form
content://contacts/people/1
as shown in first example here http://developer.android.com/reference/android/content/intent.html#intentstructure
Comments
Post a Comment