0
我有兩個編輯文本,每一個有文字守望者,當第一的EditText文本改變時改變第二的EditText文本,似乎代碼創建一個循環,是有什麼我可以做,使文本守望者只聽用戶輸入,而不是通過代碼改變文本?的EditText addTextChangedListener環
et1.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
double x = Double.valueOf(et1.getText().toString());
et2.setText(String.valueOf((x*2)));
}
});
et2.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
double x = Double.valueOf(et2.getText().toString());
et1.setText(String.valueOf((x/2)));
}
});
可以use'FocusChangeListener()'本' –
公共無效afterTextChanged(編輯S){如果(mIsCalledFromWatcher!){mIsCalledFromWatcher = TRUE;/*做的東西*/mIsCalledFromWatcher = false; }}'... [看看TextView.setText()](https://github.com/android/platform_frameworks_base/blob/master/core/java/android/widget/TextView.java#L4211)看發生了什麼... setText導致另一個afterTextChanged調用 – Selvin
你已經構建了一個無限循環 – jr593