2011-09-18 23 views
0

下面是我的代码:强制关闭时,附加的setText()

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()的应用程序工作正常

+0

http://stackoverflow.com/questions/7459966/android-change-edittext-after-each-change 请参阅您刚才的问题。 – PH7

+0

当应用程序强行关闭时,logcat中通常有确切的原因。请发布您的logcat。 – Salw

回答

3

你陷在你的afterTextChanged方法,因为在你之后setText,它被再次调用,并且再次,并且再次...你必须找到另一种方式,如何/何时追加“ - ”字符。

+0

如何解决? – Dev

+0

试着想一下,你什么时候需要“ - ”。你写完东西后是否正确?或者当你按下某个按钮时,它足够了。 –

+0

写完东西 – Dev