First look at my code:
It is in my work;
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")); } } }
Purpose: when the user enters a value in the text1 area, I want to call the text2 area. But when the user enters a value in the text1 area, text2 MyTextWatcher starts. There is an infinite loop. How can I solve this problem?
source share