In my test app, I wrote in onCreate
edit1 = (EditText) findViewById(R.id.editText_test1);
edit1.addTextChangedListener(new edittext_TextWatcher());
This is my 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
}
}
When the activity starts, it prints the log below
tag------no
but when I add this code below edit1.addTextChangedListener(new edittext_TextWatcher()):
edit1.setText("0000");
edit1.setText("1111");
edit1.setText("2222");
tag------0000
tag------1111
tag------2222
tag------2222
The last one is repeated!
who can tell me the reason,why?