0

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

K-ballo
  • 80,396
  • 20
  • 159
  • 169
Dev
  • 505
  • 2
  • 8
  • 16
  • http://stackoverflow.com/questions/7459966/android-change-edittext-after-each-change Refer to your previous question. – PH7 Sep 18 '11 at 09:14
  • When app is force closed there is usually exact reason in logcat. Please post your logcat. – Salw Sep 18 '11 at 11:29

2 Answers2

3

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.

peter.bartos
  • 11,855
  • 3
  • 51
  • 62
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

Community
  • 1
  • 1
Michell Bak
  • 13,182
  • 11
  • 64
  • 121