在文本更改侦听器上的android
我有一种情况,那里有两个领域。field1和field2。改变后我想做的就是空的field2,field1反之亦然。所以最后只有一个字段有内容。
field1 = (EditText)findViewById(R.id.field1);field2 = (EditText)findViewById(R.id.field2);field1.addTextChangedListener(new TextWatcher() {
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) {
field2.setText("");
}
});field2.addTextChangedListener(new TextWatcher() {
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) {
field1.setText("");
}
});如果我只附加addTextChangedListener,它工作正常field1,但当我为两个字段执行时,应用程序崩溃。显然是因为他们试图无限期地互相改变。一旦field1改变它field2在此时 清除field2就会改变,所以它会清除field1等等......
有人建议任何解决方案?
慕仙森
交互式爱情
翻阅古今
RISEBY
随时随地看视频慕课网APP