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

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

android - CollapsingToolbarLayout: position the ExpandedText programmatically -

Listeners to visualise results of load test in JMeter -