java - How to extract String using AutoCompleteTextView? -


i know there multiple posts in stackoverflow addressing query. however, reason still failing extract string autocompletetextview. tried using onitemclicklistener purpose. unable identify going wrong.

the code :

    @override     protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     ...      addpurchaseitemname = (autocompletetextview) findviewbyid(r.id.addpurchaseproductname);      vivzhelper = new vivzdatabaseadapter(this);      string[] autocompletename = vivzhelper.getinventorynamefilterbysuppliername(vivzhelper.getsupplierid(param1));     arrayadapter<string> nameadapter = new arrayadapter<>(this, android.r.layout.simple_list_item_1, autocompletename);     addpurchaseitemname.setthreshold(1);// starts working first char     addpurchaseitemname.setadapter(nameadapter);      addpurchaseitemname.setonitemclicklistener(new adapterview.onitemclicklistener() {          public void onitemclick(adapterview<?> arg0, view arg1, int arg2, long arg3) {             itemname = string.valueof(arg0.getitematposition(arg2));         }     });  } 

i want assign value of extracted string itemname initialized @ beginning of activity. can 1 point out going wrong? have surfed multiple resources. maybe, missing something.

note :

this code posted address issue on illegalargumentexception in stackoverflow couple of days ago. since, topic of question doesn't point more problem posted here, thought posting new question make sense. hence hope, question won't down-voted or edited duplicate

update 01 : @deividi cavarzan forgot including below line of code when editing question

arrayadapter<string> nameadapter = new arrayadapter<>(this, android.r.layout.simple_list_item_1, autocompletename); 

update 02 : declaring itemname

public class addpurchase extends actionbaractivity {  autocompletetextview addpurchaseitemname; string itemname; 

try itemname on addtextchangedlistener callback

addpurchaseitemname.addtextchangedlistener(new textwatcher() {      @override     public void ontextchanged(charsequence s, int start, int before, int count) {         itemname = s.tostring();     }      @override     public void beforetextchanged(charsequence s, int start, int count, int after) {                      }      @override     public void aftertextchanged(editable s) {      } }); 

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -