android - EditText, How can control the cursor in TextWatcher? -


i have textwatcher on edittext, in method aftertextchanged, add characters edittext move cursor end of edittext continue adding text, have problems that.

like this:

public void aftertextchanged(editable s) {      if(edittext.gettext().length()==2){          // append dot edittext         edittext.append(".");         // move cursor @ end position in edittext         edittext.setselection(edittext.gettext().length());       } } 

in android 4.0v or superior, cursor stay before "." , , in 2.2v works fine, in both can't delete characters.

anyone same problem ?

grettings

you can avoid delete problem...

public class mainactivity extends activity {     int count=0;     @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);         final edittext edittext=(edittext)findviewbyid(r.id.edittext1);          edittext.addtextchangedlistener(new textwatcher() {              @override             public void ontextchanged(charsequence arg0, int arg1, int arg2, int arg3) {                 // todo auto-generated method stub              }              @override             public void beforetextchanged(charsequence arg0, int arg1, int arg2,                     int arg3) {                 // todo auto-generated method stub              }              @override             public void aftertextchanged(editable ed) {                 // todo auto-generated method stub                   if(edittext.gettext().length()==2 && count < 3){                          // append dot edittext                         edittext.append(".");                         // move cursor @ end position in edittext                         edittext.setselection(edittext.gettext().length());                       }                  count=edittext.gettext().length();             }         });     } 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -