0

以下是我的代码:

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){ }
            });

但是我让应用程序强制关闭,当删除 setText() 应用程序工作正常

4

2 回答 2

3

你被困在你的afterTextChanged方法中,因为在你之后setText,它被一次又一次地调用......你必须找到另一种方法,如何/何时附加“-”字符。

于 2011-09-18T08:48:53.503 回答
1

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

于 2011-09-18T08:54:43.133 回答