android - getItemAtPosition() How to get readable data from the selected item in a ListView -
i have listview of contacts got android contactmanager sample. list showing fine, can't figure out how info selected item, "name" , "phone number".
i can selected position, result of mcontactlist.getitematposition(position) contentresolver$cursorwrapperinner , doesn't make sense me. can't heads or tails that.
anyone know how can name/id/phone number selected item in listview?
here code.
@override public void oncreate(bundle savedinstancestate) { log.v(tag, "activity state: oncreate()"); super.oncreate(savedinstancestate); setcontentview(r.layout.choose_contact); // obtain handles ui objects maddaccountbutton = (button) findviewbyid(r.id.addcontactbutton); mcontactlist = (listview) findviewbyid(r.id.contactlist); mshowinvisiblecontrol = (checkbox) findviewbyid(r.id.showinvisible); // initialize class properties mshowinvisible = false; mshowinvisiblecontrol.setchecked(mshowinvisible); mcontactlist.setonitemclicklistener(new onitemclicklistener() { public void onitemclick(adapterview<?> parent, view view, int position, long id) { addcontactat(position); } }); mshowinvisiblecontrol.setoncheckedchangelistener(new oncheckedchangelistener() { public void oncheckedchanged(compoundbutton buttonview, boolean ischecked) { log.d(tag, "mshowinvisiblecontrol changed: " + ischecked); mshowinvisible = ischecked; populatecontactlist(); } }); // populate contact list populatecontactlist(); } /** * populate contact list based on account selected in account spinner. */ private simplecursoradapter adapter; private void populatecontactlist() { // build adapter contact entries cursor cursor = getcontacts(); string[] fields = new string[] { contactscontract.data.display_name }; adapter = new simplecursoradapter(this, r.layout.contact_entry, cursor, fields, new int[] {r.id.contactentrytext}); mcontactlist.setadapter(adapter); } /** * obtains contact list selected account. * * @return cursor for accessing contact list. */ private cursor getcontacts() { // run query uri uri = contactscontract.contacts.content_uri; string[] projection = new string[] { contactscontract.contacts._id, contactscontract.contacts.display_name }; string selection = contactscontract.contacts.in_visible_group + " = '" + (mshowinvisible ? "0" : "1") + "'"; string[] selectionargs = null; string sortorder = contactscontract.contacts.display_name + " collate localized asc"; return managedquery(uri, projection, selection, selectionargs, sortorder); } private void addcontactat(int position) { object o = mcontactlist.getitematposition(position); }
}`
@override protected void onlistitemclick(listview l, view v, int position, long ida) { super.onlistitemclick(l, v, position, ida); cursor mycursor = (cursor) getlistview().getitematposition(position); showtoast("mycursor.getstring(1) " + mycursor.getstring(1) +" ");
Comments
Post a Comment