java - Android EditText's text value to set the selected item in the Spinner -



java - Android EditText's text value to set the selected item in the Spinner -

hello if kindly help me problem. basically, goal set selected item in spinner getting value of edittext's text. spinner has been populated xml string array. i've used textwatcher's aftertextchanged method monitor changes on edittext's text value. here code seems not working.

edittext edittext = (edittext) findviewbyid(r.id.edittext1); edittext.addtextchangedlistener(edittextlistener); private textwatcher edittextlistener= new textwatcher() { @override public void ontextchanged(charsequence s, int start, int before, int count) { if (edittext .gettext().equals("1")) { spinner1.setselection(0); // 1 on spinner letter } else if(edittext .gettext().equals("2")) { spinner1.setselection(1); // 2 on spinner letter b } else { toast.maketext(this, "the letter not on alphabet!", toast.length_short).show(); } } @override public void beforetextchanged(charsequence s, int start, int count, int after) { } @override public void aftertextchanged(editable s) { } };

you creating listener not linking listener edittext want.

edittext edittext = (edittext) findviewbyid(r.id.edittext1); edittext.addtextchangedlistener(edittextlistener); private textwatcher edittextlistener= new textwatcher() { @override public void ontextchanged(charsequence s, int start, int before, int count) { if (edittext .gettext().equals("1")) { spinner1.setselection(0); // 1 on spinner letter } else if(edittext .gettext().equals("2")) { spinner1.setselection(1); // 2 on spinner letter b } else { toast.maketext(this, "the letter not on alphabet!", toast.length_short).show(); } } @override public void beforetextchanged(charsequence s, int start, int count, int after) { } @override public void aftertextchanged(editable s) { } } edittext.addtextchangedlistener(edittextlistener);

i think want.

java android

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -