开发者

Force close when add setText()

开发者 https://www.devze.com 2023-04-05 10:54 出处:网络
the following is开发者_开发问答 my code : name = (EditText)findViewById(R.id.editText1); name.addTextChangedListener(new TextWatcher(){

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

精彩评论

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