1. addTextChangedListener方法理解
- 输入框内容变化监听:当输入框内发生变化就会执行
searchBar.addTextChangedListener(new TextWatcher() { //根据输入框输入值的改变来过滤搜索
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
LogUtils.d("onTextChanged 正在改变 s = “" + s.toString() + "” start = " + start + "| before = " + before + "| count = " + count);
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
LogUtils.d("beforeTextChanged 改变之前 s = “" + s.toString() + "” start = " + start + "| count = " + count + " | after = " + after);
}
@Override
public void afterTextChanged(Editable s) {
LogUtils.d("afterTextChanged 改变之后 s = “" + s.toString()+"”");
}
});
-
执行顺序
1 . beforeTextChanged (改变之前)
2 . onTextChanged(正在改变)
3 . afterTextChanged(改变之后) -
执行的日志
2.setOnEditorActionListener方法理解
- 监听回车键:当回车键按下时执行
searchBar.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
return false;
}
});
网友评论