我想TextWatcher为多个EditText字段实现接口。目前我正在使用:text1.addTextChangedListener(this);text2.addTextChangedListener(this);然后覆盖我的Activity中的方法:public void afterTextChanged(Editable s) {}public void beforeTextChanged(CharSequence s, int start, int count, int after) {}public void onTextChanged(CharSequence s, int start, int before, int count) { // do some operation on text of text1 field // do some operation on text of text2 field }但这工作正常,但我正在寻找其他方法,以便可以明确确定当前关注的EditText领域SoftKeyboard。
3 回答
尚方宝剑之说
TA贡献1788条经验 获得超4个赞
我会这样:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
EditText e = new EditText(this);
e.addTextChangedListener(new CustomTextWatcher(e));
}
private class CustomTextWatcher implements TextWatcher {
private EditText mEditText;
public CustomTextWatcher(EditText e) {
mEditText = e;
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
public void afterTextChanged(Editable s) {
}
}
- 3 回答
- 0 关注
- 571 浏览
添加回答
举报
0/150
提交
取消