I need an EditText with a fixed Suffix. I'm using a TextWatcher to catch the onTextChanged Event, but if I change the Text again by adding my suffix it causes a stackov开发者_运维技巧erflow exception caused by an infinite recursion.
msgtextview.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
//Doing some other stuff
msgtextview.setText("Changed Text") //This cause infinite recursion
}
}
Here's the code.
I assume you're having a stack overflow because when you programmatically add the suffix, it triggers an onTextChanged event.
Have you thought about setting a flag right before you set it programmatically so the next time it's called you can know not to add the suffix?
The alternative is to only add the suffix after the user submits your form.
精彩评论