android - how to show contact list names in an AutoCompleteTextView -


i trying use names phones contact list autocompletetextview when user starts typing name show suggestions auto complete contacts. plus it's done within custom dialog.

but doesn't work.

here relevant code:

autocompletetextview friendname;           case r.id.add_debt_menu:              // custom dialog             final dialog dialog = new dialog(this);             dialog.setcontentview(r.layout.add_debt_dialog);             dialog.settitle("add debt");               friendname = (autocompletetextview)dialog.findviewbyid(r.id.name);              cursor cursor = getcontentresolver().query(contactscontract.contacts.content_uri,null,null,null,null);      while (cursor.movetonext()){          name = cursor.getstring(cursor.getcolumnindex(contactscontract.contacts.display_name));          arraylist<string> contacts = new arraylist<>();         contacts.add(name);      }     cursor.close();       arrayadapter<string> adapter = new arrayadapter(this,android.r.layout.simple_dropdown_item_1line,contacts);     friendname.setadapter(adapter); 

solved! used:

cursor cursor = getcontentresolver().query(contactscontract.commondatakinds.phone.content_uri, null, null, null, null);             while (cursor.movetonext()) {                 string name = cursor.getstring(cursor.getcolumnindex(contactscontract.commondatakinds.phone.display_name)); 

so key using commondatakinds. still have no idea though why didn't work other method.


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -