1 searchet.addTextChangedListener(new TextWatcher() { 2 @Override 3 public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { 4 } 5 6 @Override 7 public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { 8 Toast.makeText(SearchActivity.this, charSequence, Toast.LENGTH_SHORT).show(); 9 switch (charSequence.toString()){ 10 case "":searchtv.setText("取消");break; 11 default:searchtv.setText("搜索"); 12 13 } 14 15 } 16 17 @Override 18 public void afterTextChanged(Editable editable) { 19 20 } 21 })
文字改变该方法就会调用,所以是个比较好用的方法.
需要注意的是 CharSequence text,即是显示的文字信息,:利用这个如下可以查看
Toast.makeText(SearchActivity.this, charSequence, Toast.LENGTH_SHORT).show();
searchet.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
Toast.makeText(SearchActivity.this, charSequence, Toast.LENGTH_SHORT).show();
switch (charSequence.toString()){
case "":searchtv.setText("取消");break;
default:searchtv.setText("搜索");
}
}
@Override
public void afterTextChanged(Editable editable) {
}
});