Append "@gmail.com" in EditText after pressing any key from user in android -


i thinking logic given below

edittextusername.addtextchangedlistener(new textwatcher() {    @override    public void beforetextchanged(charsequence s, int start, int count, int after) {         }        @override    public void ontextchanged(charsequence s, int start, int before, int count) {     }        @override    public void aftertextchanged(editable s) {                 appendemail(edittextusername.gettext().tostring());             }         });      void appendemail(string email){         if( email.length()>=1){              edittextusername.settext("@gmail.com");     } } 

this example code not actual code. throwing stackoverflow exception.

can resolve isssue

you need check if substring "@gmail.com" exists there no need settext again. because when set text edittext calls aftertextchange again, , call appendemail , sets text again etc.

void appendemail(string email){       if(!textutils.isempty(email) && email.contains("@gmail.com")){              edittextusername.settext(email + "@gmail.com");       } 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -