W/IInputConnectionWrapper: getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper: getExtractedText on inactive InputConnection
W/IInputConnectionWrapper: getSelectedText on inactive InputConnection
W/IInputConnectionWrapper: getTextAfterCursor on inactive InputConnection
W/IInputConnectionWrapper: getTextBeforeCursor on inactive InputConnection
我出现这种问题的情况是:
对一个输入框添加了输入监听,但是在监听中又对这个输入框进行了一次赋值,导致循环赋值,最终造成应用卡死。
错误代码:
appCompatEditText.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
double a = 1;
double b = 2;
appCompatEditText.setText((Math.min(a, b))+"");
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
@Override
public void afterTextChanged(Editable s) {
}
});
修改后:
double a = 1;
double b = 2;
appCompatEditText.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
if(a<b){
appCompatEditText.setText(a+"");
a = 0;
b = 0;
}
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
@Override
public void afterTextChanged(Editable s) {
}
});
总结:在输入监听中,不要没有判断条件的对此输入框赋值