开发者

Android EditText with a Fixed Suffix

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜