首先看我的代碼:無限循環錯誤EditText
這些是我的活動;
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被觸發。有一個無限循環。我怎麼能解決這個問題?
只是好奇......是不是' text.equel(「」)'給你一個編譯錯誤? – Ahmad 2013-04-27 23:15:38
我不復制/粘貼我的代碼。只需再次寫。(: – Twinsens 2013-04-27 23:19:51