java - How to Custom Autocomplete TextView? -


i tried make search task of telephone directory, don't know problem.

this's code:

in adapter:

public class listcontactadapter extends arrayadapter<contact> {     private  context context;     private int layoutresourceid;   private list<contact> contact;     public listcontactadapter(context context, int layoutresourceid, list<contact> contact) {         super(context, layoutresourceid, contact);         this.context = context;         this.layoutresourceid = layoutresourceid;         this.contact = contact;     }     public view getview(final int position, view convertview, viewgroup parent) {         textview tvphonenumber;         textview tvname;         view row = convertview;         layoutinflater inflater = ((activity) context).getlayoutinflater();         row = inflater.inflate(layoutresourceid, parent, false);         tvphonenumber= (textview) row.findviewbyid(r.id.textviewphoneno);         tvname = (textview) row.findviewbyid(r.id.textviewname);         final contact data = contact.get(position);         tvphonenumber.settext(data.getphonenumber());         tvname.settext(data.getname());         return row;      } } 

and main:

public class customcompletextview extends actionbaractivity { autocompletetextview auto;     list<contact> listcontact =new arraylist<>();     listview listviewcontact;     @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.layout_complete_textview);         contentresolver cr = getcontentresolver();         cursor cur = cr.query(contactscontract.contacts.content_uri, null, null, null, null);         if (cur.getcount() > 0) {             while (cur.movetonext()) {                 contact = new contact(null,null);                 string id = cur.getstring(cur.getcolumnindex(                         contactscontract.contacts._id));                 string name = cur.getstring(cur.getcolumnindex(                         contactscontract.contacts.display_name));                 if (integer.parseint(cur.getstring(cur.getcolumnindex(                         contactscontract.contacts.has_phone_number))) > 0) {                     cursor pcur = cr.query(                             contactscontract.commondatakinds.phone.content_uri,                             null,                             contactscontract.commondatakinds.phone.contact_id +" = ?",                             new string[]{id}, null);                     while (pcur.movetonext()) {                         a.setname(name);                         string phonenumber = pcur.getstring(pcur.getcolumnindex(                                 contactscontract.commondatakinds.phone.number));                         a.setphonenumber(phonenumber);                         listcontact.add(a);                     }                     pcur.close();                 }             }         }          listcontactadapter adapter = new listcontactadapter(this,r.layout.layout_item,listcontact);       auto= (autocompletetextview) findviewbyid(r.id.textviewauto);          auto.setthreshold(3);         auto.setadapter(adapter);      } 

i tried run listview , worked. can tell me wrong, much.


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -