android - How to AutoCompleteTextView into Dialog -


i have problem android program wheere need put autocompletetextview dialog not working.

i share code:

public class registeractivity extends appcompatactivity { private expandablelistview mylist; private list<convenios> conveniolist; private arraylist<string> convenionames = new arraylist<string>();  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_register); }  public void cadastrarnovoconvenio(view view) {     cadastraconvenio(); } private void cadastraconvenio()  {     final dialog dialog = new dialog(this);     dialog.setcontentview(r.layout.add_new_convenio);      final radiogroup tipoconvenio = (radiogroup) dialog.findviewbyid(r.id.rbg);     final button save = (button) dialog.findviewbyid(r.id.bt_cadastrar);     final button cancel = (button) dialog.findviewbyid(r.id.bt_cancelar);      final autocompletetextview conveniotextview = (autocompletetextview) findviewbyid(r.id.autocompletetextviewconvenio);      dialog.settitle("add new item:");      arrayadapter<string> adapter = new arrayadapter<string>(this, android.r.layout.simple_list_item_1, convenionames);     conveniotextview.setadapter(adapter);     conveniotextview.setthreshold(1);      //exibe na tela o dialog     dialog.show();   } 

the problem occurs in code line:

 conveniotextview.setadapter(adapter);  conveniotextview.setthreshold(1); 

you requesting autocomplitetextview activity view. in dialog view. have null in autocomplitetextview variable , nullpointerexception on conveniotextview.setadapter(adapter).

you need change code:

    final autocompletetextview conveniotextview = (autocompletetextview) findviewbyid(r.id.autocompletetextviewconvenio) 

to this:

    final autocompletetextview conveniotextview = (autocompletetextview) dialog.getview().findviewbyid(r.id.autocompletetextviewconvenio); 

Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -