首先看我的代码:
这些在我的活动中;
EditText text1,text2; (Are defined corretly not problem)
text1.addTextChangedListener(new MyTextWatcher(onePercent));
text2.addTextChangedListener(new MyTextWatcher(twoPercent));
.. ..
.. ..
.. ..
private class MyTextWatcher implements TextWatcher {
private View view;
private MyTextWatcher(View view) {
this.view = view;
}
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {}
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2)
{}
public void afterTextChanged(Editable editable) {
String text = editable.toString();
switch(view.getId()){
case R.id.dis_one_percent: (this is text1)
if(!text.equel(""))
text2.setText(Double.toString(text));
break;
case R.id.dis_one_number: (and text2)
if(!text.equel(""))
text1.setText(Double.toString(text+"LOL"));
}
}
}
目标:当用户在 text1 区域输入一些值时,我想触发 text2 区域。但是当用户在 text1 区域输入值时,会触发 text2 的 MyTextWatcher。有一个无限循环。我该如何解决这个问题?