开发者

Force close when add setText()

the following is开发者_开发问答 my code :

name = (EditText)findViewById(R.id.editText1);
        name.addTextChangedListener(new TextWatcher(){
         public void afterTextChanged(Editable s) {


             name.setText(s.toString()+"-");
                }
 public void beforeTextChanged(CharSequence s, int start, int count, int after){ }
 public void onTextChanged(CharSequence s, int start, int before, int count){ }
            });

But I get the app to force close , when remove setText() the app works fine


You are getting stuck in your afterTextChanged method, because right after you setText, it is called again, and again, and again... You have to find another way, how/when to append the "-" character.


Please check this question I asked some time ago. It's a lot like your question:

Changing text in Android on text change causes overflow error

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜