在用到addChangeTextListener
的時候,一按鍵屏幕就不動了,代碼如下:
email = (EditText) findViewById(R.id.email);
email.addTextChangedListener(new TextWatcher()
{
@Override
public void afterTextChanged(Editable s)
{
if (email.getText().toString().matches("[a-zA-Z0-9._-]+@[a-z]+\\.+[a-z]+")
&& s.length() > 0)
error.setText("valid email");
else
email.setText("invalid email");
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1,int arg2, int arg3)
{
}
@Override
public void onTextChanged(CharSequence arg0, int arg1,int arg2, int arg3)
{
}
});
email.setText("invalid email");
上面的代碼應該是:
error.setText("invalid email");
使用setText()
, 再次觸發afterTextChanged()