В моем приложении есть два EditText и один TextView.Я установил Two Textwatcher на оба EditText.В зависимости от значения в этом EditText, значение другого EditText изменяется, и это также применяется к textView.Все идет хорошо.Но если я добавлю этот другой текст редактирования как значение, которое будет изменено на основе другого текста редактирования, то это даст мне ошибку stackOverflow.Я не знаю, где я не прав.И я не могу поставить TextWatcher для обоих EditText, чтобы изменить значение по отношению друг к другу.
Пожалуйста, помогите мне для этого.Благодарю.Код:
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 и помогите мне решить его.Спасибо.