In the code provided there are 3 times setText
executed for TextView
. So, it keeps the result only of the last call. If you want to display result of all replacements, do it in single String:
et.removeTextChangedListener(tt);
tv.setText(et.getText().toString().replace("a", "1").replace("b", "2").replace("c", "3"));
et.addTextChangedListener(tt);
EDIT:
Of course, you can execute transformation step-by-step:
et.removeTextChangedListener(tt);
String s = et.getText().toString();
s = s.replace("a", "1");
s = s.replace("b", "2");
s = s.replace("c", "3");
tv.setText(s);
et.addTextChangedListener(tt);
Method String.replace
doesn't change String, but returns new one, so we need to reassign results of each replacement (I just assign to s
again and again to prevent unused references)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…