android - How do I bind contact cursor data to a MultiAutoCompleteTextView with chips -
i have been @ 2 weeks now. believe have come close, can't quite final product work. have functionality similar email in app. instead of email addresses, uses phone numbers. gmail app on android able use multiautocompletetextview with chips display recipient email addresses. want do. through research , trials, able create multiautocompletetextview, without chips. there number of questions , answers here on same subject. invariably, none of ones find has example binds data user's contact book multiautocompletetextview. examples see use own made simple arrays, if final step trivial. final step stuck. each time try bind contact book multiautocompletetextview chips, code fails. question quite extremely specific: how bind contact book multiautocompletetextview chips? context, have read chips widget in android application , bunch of other articles , responses besides. aware of specific use case? gmail use case?
edit
following code use https://github.com/splitwise/tokenautocomplete . getview
of adapter never called.
code bind adapter edittext
madapter = new contactadapter(getactivity(), mpeoplelist, r.layout.contacts_row); multiedit = (contactsautocompleteview) view.findviewbyid(r.id.multi_edit); multiedit.setadapter(madapter);
code load contact book
public void populatepeoplelist() { mpeoplelist.clear(); cursor people = getactivity().getcontentresolver().query(contactscontract.contacts.content_uri, null, null, null, null); while (people.movetonext()) { string contactname = people.getstring(people.getcolumnindex(contactscontract.contacts.display_name)); string contactid = people.getstring(people.getcolumnindex(contactscontract.contacts._id)); string hasphone = people.getstring(people.getcolumnindex(contactscontract.contacts.has_phone_number)); if (integer.parseint(hasphone) > 0) { // know have number query cursor phones = getactivity().getcontentresolver().query(contactscontract.commondatakinds.phone.content_uri, null, contactscontract.commondatakinds.phone.contact_id + " = " + contactid, null, null); while (phones.movetonext()) { // store numbers , display dialog letting user select which. string phonenumber = phones.getstring(phones.getcolumnindex(contactscontract.commondatakinds.phone.number)); string numbertype = phones.getstring(phones.getcolumnindex(contactscontract.commondatakinds.phone.type)); if (numbertype.equals("0")) { numbertype = "work"; } else if (numbertype.equals("1")) { numbertype = "home"; } else if (numbertype.equals("2")) { numbertype = "mobile"; } else { numbertype = "other"; } mpeoplelist.add(new contact(contactname, phonenumber, numbertype)); } phones.close(); } } people.close(); getactivity().startmanagingcursor(people); }
my adapter
public class contactadapter extends arrayadapter<contact> { private final context mcontext; private final int mrowresourceid; private final layoutinflater minflater; arraylist<contact> mcontacts; public contactadapter(context context, arraylist<contact> contacts, int contactsrow) { super(context, contactsrow, contacts); mcontext = context; mrowresourceid = contactsrow; minflater = (layoutinflater) context.getsystemservice(context.layout_inflater_service); mcontacts = contacts; } @override public view getview(int position, view convertview, viewgroup parent) { view rowview = convertview; if (null == rowview) { rowview = minflater.inflate(mrowresourceid, parent, false); viewholder viewsholder = new viewholder(); viewsholder.name = (textview) rowview.findviewbyid(r.id.contact_name); viewsholder.phone = (textview) rowview.findviewbyid(r.id.contact_phone); viewsholder.type = (textview) rowview.findviewbyid(r.id.contact_type); rowview.settag(viewsholder); } viewholder viewsholder = (viewholder) rowview.gettag(); contact con = mcontacts.get(position);// getitem(position); viewsholder.name.settext(con.getname()); viewsholder.phone.settext(con.getphone()); viewsholder.type.settext(con.gettype()); return rowview; } static class viewholder { textview name; textview phone; textview type; } }
my contact object: accessors , constructor not shown
public class contact implements serializable { private static final long serialversionuid = 1l; private string name; private string phone; private string type; }
my tokencompletetextview: ?? goes inside defaultobject
public class contactsautocompleteview extends tokencompletetextview { public contactsautocompleteview(context context, attributeset attrs) { super(context, attrs); } @override protected view getviewforobject(object object) { contact p = (contact) object; layoutinflater l = (layoutinflater) getcontext().getsystemservice(activity.layout_inflater_service); relativelayout view = (relativelayout) l.inflate(r.layout.contacts_row, (viewgroup) contactsautocompleteview.this.getparent(), false); ((textview) view.findviewbyid(r.id.contact_name)).settext(p.getname()); ((textview) view.findviewbyid(r.id.contact_phone)).settext(p.getphone()); ((textview) view.findviewbyid(r.id.contact_type)).settext(p.gettype()); return view; } @override protected object defaultobject(string completiontext) { //what goes here? } @override public void setselected(boolean selected) { super.setselected(selected); }
}
few weeks ago in situation, , did use library chips
i used this one
as bind contacts more specific stuck , ?
Comments
Post a Comment