在我的测试应用中,我写了onCreate
edit1 = (EditText) findViewById(R.id.editText_test1);
edit1.addTextChangedListener(new edittext_TextWatcher());
这是我的textwatcher
public class edittext_TextWatcher implements TextWatcher{
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
String str=s.toString();
if(str.equals(""))
Log.e("tag", "no");
else
Log.e("tag", str);
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,int after) {
// TODO Auto-generated method stub
}
@Override
public void onTextChanged(CharSequence s, int start, int before,int count) {
// TODO Auto-generated method stub
}
}
当活动开始时,它会打印下面的日志
tag------no
但当我在edit1.addTextChangedListener(new edittext_TextWatcher())下面添加此代码时:
edit1.setText("0000");
edit1.setText("1111");
edit1.setText("2222");
tag------0000
tag------1111
tag------2222
tag------2222
最后一个重复!
谁能告诉我原因,为什么?