为什么不能将两个 TextWatcher 放在一个活动中,用于两个不同的编辑文本,从而相互更改值?
在我的应用程序中有两个 EditText 和一个 TextView。 我已经在这两个 EditText 上设置了两个 Textwatcher。根据该 EditText 中的值,更改另一个 EditText 的值,并且它也适用于 textView。 一切顺利。但是,如果我将另一个 Edittext 的值设置为基于另一个 EditText 进行更改,那么它会给我 stackOverflow 错误。 我不知道我错在哪里。我无法为两个 EditText 添加 TextWatcher 来更改彼此的值。
请帮助我。 谢谢。 代码:
amountText.setText(""); // TextView
excludedText.setText(""); // EditText
includedText.setText(""); // EditText
includedText.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if(!(includedText.getText().toString().equals("")))
{
double included = Double.parseDouble(includedText.getText().toString());
included = roundTwoDecimals(included);
// double amountValue = (excluded*15/100);
String amt = String.valueOf(roundTwoDecimals(included-(included/1.15)));
String excluded = String.valueOf(included/1.15);
System.out.println("The Amount is: "+amt);
amountText.setText(amt);
try{
excludedText.setText("");
excludedText.setText(excluded); //////// Error Line
}
catch(Exception e)
{
e.printStackTrace();
}
}
else
{
amountText.setText("");
excludedText.setText(""); // Error line
}
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
}
});
excludedText.addTextChangedListener(new TextWatcher()
{
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if(!(excludedText.getText().toString().equals("")))
{
double excluded = Double.parseDouble(excludedText.getText().toString());
excluded = roundTwoDecimals(excluded);
String amt = String.valueOf(roundTwoDecimals(excluded*0.15));
String included = String.valueOf(roundTwoDecimals(excluded+(excluded*0.15)));
System.out.println("The Amount is: "+amt);
amountText.setText(amt);
includedText.setText(included);
}
else
{
amountText.setText("");
includedText.setText("");
}
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
}
});
我的Logcat是:
10-11 09:47:28.288: ERROR/AndroidRuntime(363): FATAL EXCEPTION: main
10-11 09:47:28.288: ERROR/AndroidRuntime(363): java.lang.StackOverflowError
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.text.DynamicLayout.reflow(DynamicLayout.java:261)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.text.DynamicLayout.<init>(DynamicLayout.java:150)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.makeNewLayout(TextView.java:4851)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.checkForRelayout(TextView.java:5348)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.setText(TextView.java:2688)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.setText(TextView.java:2556)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.EditText.setText(EditText.java:75)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.setText(TextView.java:2531)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at com.project.TaxCalculator.GSTActivity$1.onTextChanged(GSTActivity.java:73)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.sendOnTextChanged(TextView.java:6131)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.setText(TextView.java:2691)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.setText(TextView.java:2556)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.EditText.setText(EditText.java:75)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.setText(TextView.java:2531)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at com.project.TaxCalculator.GSTActivity$2.onTextChanged(GSTActivity.java:111)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.sendOnTextChanged(TextView.java:6131)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.setText(TextView.java:2691)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.setText(TextView.java:2556)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.EditText.setText(EditText.java:75)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.setText(TextView.java:2531)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at com.project.TaxCalculator.GSTActivity$1.onTextChanged(GSTActivity.java:73)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.sendOnTextChanged(TextView.java:6131)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.setText(TextView.java:2691)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.setText(TextView.java:2556)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.EditText.setText(EditText.java:75)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.setText(TextView.java:2531)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at com.project.TaxCalculator.GSTActivity$2.onTextChanged(GSTActivity.java:111)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.sendOnTextChanged(TextView.java:6131)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.setText(TextView.java:2691)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.setText(TextView.java:2556)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.EditText.setText(EditText.java:75)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.setText(TextView.java:2531)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at com.project.TaxCalculator.GSTActivity$1.onTextChanged(GSTActivity.java:73)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.sendOnTextChanged(TextView.java:6131)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.setText(TextView.java:2691)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.setText(TextView.java:2556)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.EditText.setText(EditText.java:75)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.setText(TextView.java:2531)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at com.project.TaxCalculator.GSTActivity$2.onTextChanged(GSTActivity.java:111)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.sendOnTextChanged(TextView.java:6131)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.setText(TextView.java:2691)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.setText(TextView.java:2556)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.EditText.setText(EditText.java:75)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.setText(TextView.java:2531)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at com.project.TaxCalculator.GSTActivity$1.onTextChanged(GSTActivity.java:73)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.sendOnTextChanged(TextView.java:6131)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.setText(TextView.java:2691)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.setText(TextView.java:2556)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.EditText.setText(EditText.java:75)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.setText(TextView.java:2531)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at com.project.TaxCalculator.GSTActivity$2.onTextChanged(GSTActivity.java:111)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.sendOnTextChanged(TextView.java:6131)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.setText(TextView.java:2691)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.setText(TextView.java:2556)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.EditText.setText(EditText.java:75)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.setText(TextView.java:2531)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at com.project.TaxCalculator.GSTActivity$1.onTextChanged(GSTActivity.java:73)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.sendOnTextChanged(TextView.java:6131)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.setText(TextView.java:2691)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.setText(TextView.java:2556)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.EditText.setText(EditText.java:75)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.setText(TextView.java:2531)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at com.project.TaxCalculator.GSTActivity$2.onTextChanged(GSTActivity.java:111)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.sendOnTextChanged(TextView.java:6131)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.setText(TextView.java:2691)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextVie
请参考这个logcat并帮助我解决它。 谢谢。
In My Application there is two EditText and one TextView.
I have set the Two Textwatcher on that both EditText. Based on the Value in that EditText, The Value of another EditText is changed and it also apply to textView.
All Goes Nice. But if i put the that Another Edittext as like the value of it to be change based on the Another EditText then it gives me stackOverflow Error.
I dont know Where i am wrong. And I am not able to Put the TextWatcher for both the EditText to change the value with respect to each other.
Please Help me for it.
Thanks.
Code :
amountText.setText(""); // TextView
excludedText.setText(""); // EditText
includedText.setText(""); // EditText
includedText.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if(!(includedText.getText().toString().equals("")))
{
double included = Double.parseDouble(includedText.getText().toString());
included = roundTwoDecimals(included);
// double amountValue = (excluded*15/100);
String amt = String.valueOf(roundTwoDecimals(included-(included/1.15)));
String excluded = String.valueOf(included/1.15);
System.out.println("The Amount is: "+amt);
amountText.setText(amt);
try{
excludedText.setText("");
excludedText.setText(excluded); //////// Error Line
}
catch(Exception e)
{
e.printStackTrace();
}
}
else
{
amountText.setText("");
excludedText.setText(""); // Error line
}
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
}
});
excludedText.addTextChangedListener(new TextWatcher()
{
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if(!(excludedText.getText().toString().equals("")))
{
double excluded = Double.parseDouble(excludedText.getText().toString());
excluded = roundTwoDecimals(excluded);
String amt = String.valueOf(roundTwoDecimals(excluded*0.15));
String included = String.valueOf(roundTwoDecimals(excluded+(excluded*0.15)));
System.out.println("The Amount is: "+amt);
amountText.setText(amt);
includedText.setText(included);
}
else
{
amountText.setText("");
includedText.setText("");
}
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
}
});
Here my Logcat is:
10-11 09:47:28.288: ERROR/AndroidRuntime(363): FATAL EXCEPTION: main
10-11 09:47:28.288: ERROR/AndroidRuntime(363): java.lang.StackOverflowError
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.text.DynamicLayout.reflow(DynamicLayout.java:261)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.text.DynamicLayout.<init>(DynamicLayout.java:150)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.makeNewLayout(TextView.java:4851)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.checkForRelayout(TextView.java:5348)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.setText(TextView.java:2688)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.setText(TextView.java:2556)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.EditText.setText(EditText.java:75)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.setText(TextView.java:2531)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at com.project.TaxCalculator.GSTActivity$1.onTextChanged(GSTActivity.java:73)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.sendOnTextChanged(TextView.java:6131)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.setText(TextView.java:2691)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.setText(TextView.java:2556)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.EditText.setText(EditText.java:75)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.setText(TextView.java:2531)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at com.project.TaxCalculator.GSTActivity$2.onTextChanged(GSTActivity.java:111)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.sendOnTextChanged(TextView.java:6131)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.setText(TextView.java:2691)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.setText(TextView.java:2556)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.EditText.setText(EditText.java:75)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.setText(TextView.java:2531)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at com.project.TaxCalculator.GSTActivity$1.onTextChanged(GSTActivity.java:73)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.sendOnTextChanged(TextView.java:6131)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.setText(TextView.java:2691)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.setText(TextView.java:2556)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.EditText.setText(EditText.java:75)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.setText(TextView.java:2531)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at com.project.TaxCalculator.GSTActivity$2.onTextChanged(GSTActivity.java:111)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.sendOnTextChanged(TextView.java:6131)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.setText(TextView.java:2691)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.setText(TextView.java:2556)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.EditText.setText(EditText.java:75)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.setText(TextView.java:2531)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at com.project.TaxCalculator.GSTActivity$1.onTextChanged(GSTActivity.java:73)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.sendOnTextChanged(TextView.java:6131)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.setText(TextView.java:2691)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.setText(TextView.java:2556)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.EditText.setText(EditText.java:75)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.setText(TextView.java:2531)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at com.project.TaxCalculator.GSTActivity$2.onTextChanged(GSTActivity.java:111)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.sendOnTextChanged(TextView.java:6131)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.setText(TextView.java:2691)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.setText(TextView.java:2556)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.EditText.setText(EditText.java:75)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.setText(TextView.java:2531)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at com.project.TaxCalculator.GSTActivity$1.onTextChanged(GSTActivity.java:73)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.sendOnTextChanged(TextView.java:6131)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.setText(TextView.java:2691)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.setText(TextView.java:2556)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.EditText.setText(EditText.java:75)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.setText(TextView.java:2531)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at com.project.TaxCalculator.GSTActivity$2.onTextChanged(GSTActivity.java:111)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.sendOnTextChanged(TextView.java:6131)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.setText(TextView.java:2691)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.setText(TextView.java:2556)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.EditText.setText(EditText.java:75)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.setText(TextView.java:2531)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at com.project.TaxCalculator.GSTActivity$1.onTextChanged(GSTActivity.java:73)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.sendOnTextChanged(TextView.java:6131)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.setText(TextView.java:2691)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.setText(TextView.java:2556)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.EditText.setText(EditText.java:75)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.setText(TextView.java:2531)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at com.project.TaxCalculator.GSTActivity$2.onTextChanged(GSTActivity.java:111)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.sendOnTextChanged(TextView.java:6131)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextView.setText(TextView.java:2691)
10-11 09:47:28.288: ERROR/AndroidRuntime(363): at android.widget.TextVie
Please refer this logcat and help me to solve it.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是 stackoverflow 的问题,你将陷入无限循环。
您正在从第二个编辑文本更新一个编辑文本的值,反之亦然。
例如::
当您在第一个编辑文本中输入字符时,它将设置第二个编辑文本的文本,此时在第二个编辑文本中,您编写了一段代码来设置第一个编辑文本的文本,这样您将进入无限循环。
编辑
This is a problem of
stackoverflow
you are going to infinite loop.You are updating value of one edittext from second one and vice-verse .
For example ::
When you enter character in first edit text it will set text of second edit text and at that time in second edit text you have write a code to set text of first edit text so that you are going to infinite loop.
EDIT
您可以尝试将代码放入“afterTextChanged”中,但我认为这会导致相同的无限循环。这就是为什么我不明白两个输入如何相互依赖,也就是说,如果 EditText-A 更改了 ET-B 的文本,那么 ET-B 如何再次更改 ET-A 中的文本,这并不意味着任何意义。
You could try to put the code into "afterTextChanged", but I think it will result in the same infinite loop. That's why I don't understand how both inputs can depend on each other, meaning, if EditText-A changes the text of ET-B, then how can ET-B change the text in ET-A again, that doesn't make any sense.
每次在 EditText 中更改文本时,都会调用 TextWatcher(如果已定义它并且取决于您实现的重写方法)。因此,根据您想要实现的目标,如果编辑 EditText A 的文本,则调用 TextWatcher 并编辑 EditText B 的文本,然后调用其相应的 TextWatcher,后者编辑 EditText A 的文本,然后调用...简而言之,这是一种不好的做法。
Everytime a text is changed in an EditText the TextWatcher is invoked (if it is defined and depending on which overridden methods you implemented). So based on what you want to accomplish, if EditText A's text is edited then the TextWatcher is invoked and edits EditText B's text which then invokes its corresponding TextWatcher which edits EditText A's text which invokes... in short it is a bad practice.