TextWatcher in Android -
i have edittext having maximum supporting character of 10. want when type count should decrement , on backspace count should increment.....
private static textview messagecount=null; messagecount=(textview) findviewbyid(r.id.messagecount); mmessagefield.addtextchangedlistener(new textwatcher() { @override public void ontextchanged(charsequence s, int start, int before, int count) { } @override public void beforetextchanged(charsequence s, int start, int count, int after) { } @override public void aftertextchanged(editable s) { if(count>0) { count--; messagecount.settext("count=>"+count); //toast.maketext(mcontext, "count=>"+count, toast.length_long).show(); } } });
try this:
@override public void ontextchanged(charsequence s, int start, int before, int count) { int count1 = 10 - mmessagefield.gettext().tostring().length(); messagecount.settext("count=>"+string.valueof(count1)); }
it tell length of textview. put inside "ontextchanged" doing length increase or decrease according text enter or delete.
Comments
Post a Comment