首页 > 代码库 > Android之怎样设置文本改变监听

Android之怎样设置文本改变监听

文本改变监听:

username为EditText的一个对象

username.addTextChangedListener(new TextWatcher() {


@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
//參数依次代表的意思:s文本内容,start从第几个字符開始改变,before(自己能够測试一下。我没測试),count改变的字符个数
// TODO Auto-generated method stub
Log.i("editText", s.toString());
}


@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
Log.i("editText beforeTextChanged", s.toString());


}


@Override
public void afterTextChanged(Editable s) {
Log.i("editText  afterTextChanged", s.toString());
// TODO Auto-generated method stub


}
});

Android之怎样设置文本改变监听