Last character taken twice by textwatcher

assume that you have a string like Shoe , so the statement

s.length() - 1 

will return 3 , keep in mind that array index in java will start from 0 , so

s.charAt(s.length() - 1)

will return character “e” again. then in your if else clause you append “e” to your String and the result would be “Shoee”

Edit: according to your comment,assume an empty String , so you enter first letter “s” so the s would be append to your content as expected,you enter second word “h” so that the character append to your content would be “h” so on to letter “e”, but if you put space after “shoe” you have “shoe” in your content and your if statement would never be run and your last word would be repeated because of you check your char with == which is incorrect for String or charSequence . you should use equal() instead :

if((“\n”).equals(c))

Leave a Comment