I am going to change the text of the edittext based on the value enter on the another edittext. and also like same thig with visa-versa.
For that i have use the TextChanged Listener and implemented as like below:
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);
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);
excludedText.setText(excluded); //////// Error Line
}
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
@Override
public void afterTextChanged(Editable s) {
}
});
// worked
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);
}
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
@Override
public void afterTextChanged(Editable s) {
}
});
}
But after doing this i am not able to get the text change. for Secod EditText its worked nice but while i use the First EditText then it gives me error at the commented line.
Error Log:
12-22 13:08:17.640: ERROR/AndroidRuntime(1077): FATAL EXCEPTION: main
12-22 13:08:17.640: ERROR/AndroidRuntime(1077): java.lang.StackOverflowError
12-22 13:08:17.640: ERROR/AndroidRuntime(1077): at android.text.TextUtils.getChars(TextUtils.java:69)
12-22 13:08:17.640: ERROR/AndroidRuntime(1077): at android.text.TextUtils.indexOf(TextUtils.java:102)
12-22 13:08:17.640: ERROR/AndroidRuntime(1077): at android.text.StaticLayout.generate(StaticLayout.java:131)
12-22 13:08:17.640: ERROR/AndroidRuntime(1077): at android.text.DynamicLayout.reflow(DynamicLayout.java:261)
12-22 13:08:17.640: ERROR/AndroidRuntime(1077): at android.text.DynamicLayout.<init>(DynamicLayout.java:150)
12-22 13:08:17.640: ERROR/AndroidRuntime(1077): at android.widget.TextView.makeNewLayout(TextView.java:4851)
12-22 13:08:17.640: ERROR/AndroidRuntime(1077): at android.widget.TextView.checkForRelayout(TextView.java:5348)
12-22 13:08:17.640: ERROR/AndroidRuntime(1077): at android.widget.TextView.setText(TextView.java:2688)
12-22 13:08:17.640: ERROR/AndroidRuntime(1077): at android.widget.TextView.setText(TextView.java:2556)
12-22 13:08:17.640: ERROR/AndroidRuntime(1077): at android.widget.EditText.setText(EditText.java:75)
12-22 13:08:17.640: ERROR/AndroidRuntime(1077): at android.widget.TextView.setText(TextView.java:2531)
12-22 13:08:17.640: ERROR/AndroidRuntime(1077): at com.project.TaxCalculator.GSTActivity$2.onTextChanged(GSTActivity.java:93)
12-22 13:08:17.640: ERROR/AndroidRuntime(1077): at android.widget.TextView.sendOnTextChanged(TextView.java:6131)
12-22 13:08:17.640: ERROR/AndroidRuntime(1077): at android.widget.TextView.setText(TextView.java:2691)
12-22 13:08:17.640: ERROR/AndroidRuntime(1077): at android.widget.TextView.setText(TextView.java:2556)
12-22 13:08:17.640: ERROR/AndroidRuntime(1077): at android.widget.EditText.setText(EditText.java:75)
12-22 13:08:17.640: ERROR/AndroidRuntime(1077): at android.widget.TextView.setText(TextView.java:2531)
12-22 13:08:17.640: ERROR/AndroidRuntime(1077): at com.project.TaxCalculator.GSTActivity$1.afterTextChanged(GSTActivity.java:74)
12-22 13:08:17.640: ERROR/AndroidRuntime(1077): at android.widget.TextView.sendAfterTextChanged(TextView.java:6145)
12-22 13:08:17.640: ERROR/AndroidRuntime(1077): at android.widget.TextView.setText(TextView.java:2695)
12-22 13:08:17.640: ERROR/AndroidRuntime(1077): at android.widget.TextView.setText(TextView.java:2556)
12-22 13:08:17.640: ERROR/AndroidRuntime(1077): at android.widget.EditText.setText(EditText.java:75)
12-22 13:08:17.640: ERROR/AndroidRuntime(1077): at android.widget.TextView.setText(TextView.java:2531)
12-22 13:08:17.640: ERROR/AndroidRuntime(1077): at com.project.TaxCalculator.GSTActivity$2.onTextChanged(GSTActivity.java:93)
12-22 13:08:17.640: ERROR/AndroidRuntime(1077): at android.widget.TextView.sendOnTextChanged(TextView.java:6131)
12-22 13:08:17.640: ERROR/AndroidRuntime(1077): at android.widget.TextView.setText(TextView.java:2691)
12-22 13:08:17.640: ERROR/AndroidRuntime(1077): at android.widget.TextView.setText(TextView.java:2556)
12-22 13:08:17.640: ERROR/AndroidRuntime(1077): at android.widget.EditText.setText(EditText.java:75)
12-22 13:08:17.640: ERROR/AndroidRuntime(1077): at android.widget.TextView.setText(TextView.java:2531)
12-22 13:08:17.640: ERROR/AndroidRuntime(1077): at com.project.TaxCalculator.GSTActivity$1.afterTextChanged(GSTActivity.java:74)
12-22 13:08:17.640: ERROR/AndroidRuntime(1077): at android.widget.TextView.sendAfterTextChanged(TextView.java:6145)
12-22 13:08:17.640: ERROR/AndroidRuntime(1077): at android.widget.TextView.setText(TextView.java:2695)
12-22 13:08:17.640: ERROR/AndroidRuntime(1077): at android.widget.TextView.setText(TextView.java:2556)
12-22 13:08:17.640: ERROR/AndroidRuntime(1077): at android.widget.EditText.setText(EditText.java:75)
12-22 13:08:17.640: ERROR/AndroidRuntime(1077): at android.widget.TextView.setText(TextView.java:2531)
12-22 13:08:17.640: ERROR/AndroidRuntime(1077): at com.project.TaxCalculator.GSTActivity$2.onTextChanged(GSTActivity.java:93)
12-22 13:08:17.640: ERROR/AndroidRuntime(1077): at android.widget.TextView.sendOnTextChanged(TextView.java:6131)
12-22 13:08:17.640: ERROR/AndroidRuntime(1077): at android.widget.TextView.setText(TextView.java:2691)
12-22 13:08:17.640: ERROR/AndroidRuntime(1077): at android.widget.TextView.setText(TextView.java:2556)
12-22 13:08:17.640: ERROR/AndroidRuntime(1077): at android.widget.EditText.setText(EditText.java:75)
12-22 13:08:17.640: ERROR/AndroidRuntime(1077): at android.widget.TextView.setText(TextView.java:2531)
12-22 13:08:17.640: ERROR/AndroidRuntime(1077): at com.project.TaxCalculator.GSTActivity$1.afterTextChanged(GSTActivity.java:74)
12-22 13:08:17.640: ERROR/AndroidRuntime(1077): at android.widget.TextView.sendAfterTextChanged(TextView.java:6145)
12-22 13:08:17.640: ERROR/AndroidRuntime(1077): at android.widget.TextView.setText(TextView.java:2695)
12-22 13:08:17.640: ERROR/AndroidRuntime(1077): at android.widget.TextView.setText(TextView.java:2556)
12-22 13:08:17.640: ERROR/AndroidRuntime(1077): at android.widget.EditText.setText(EditText.java:75)
12-22 13:08:17.640: ERROR/AndroidRuntime(1077): at android.widget.TextView.setText(TextView.java:2531)
12-22 13:08:17.640: ERROR/AndroidRuntime(1077): at com.project.TaxCalculator.GSTActivity$2.onTextChanged(GSTActivity.java:93)
12-22 13:08:17.640: ERROR/AndroidRuntime(1077): at android.widget.TextView.sendOnTextChanged(TextView.java:6131)
12-22 13:08:17.640: ERROR/AndroidRuntime(1077): at android.widget.TextView.setText(TextView.java:2691)
12-22 13:08:17.640: ERROR/AndroidRuntime(1077): at android.widget.TextView.setText(TextView.java:2556)
12-22 13:08:17.640: ERROR/AndroidRuntime(1077): at android.widget.EditText.setText(EditText.java:75)
12-22 13:08:17.640: ERROR/AndroidRuntime(1077): at android.widget.TextView.setText(TextView.java:2531)
12-22 13:08:17.640: ERROR/AndroidRuntime(1077): at com.project.TaxCalculator.GSTActivity$1.afterTextChanged(GSTActivity.java:74)
12-22 13:08:17.640: ERROR/AndroidRuntime(1077): at android.widget.TextView.sendAfterTextChanged(TextView.java:6145)
12-22 13:08:17.640: ERROR/AndroidRuntime(1077): at android.widget.TextView.setText(TextView.java:2695)
12-22 13:08:17.640: ERROR/AndroidRuntime(1077): at android.widget.TextView.setText(TextView.java:2556)
12-22 13:08:17.640: ERROR/AndroidRuntime(1077): at android.widget.EditText.setText(EditText.java:75)
12-22 13:08:17.640: ERROR/AndroidRuntime(1077): at android.widget.TextView.setText(TextView.java:2531)
12-22 13:08:17.640: ERROR/AndroidRuntime(1077): at com.project.TaxCalculator.GSTActivity$2.onTextChanged(GSTActivity.java:93)
12-22 13:08:17.640: ERROR/AndroidRuntime(1077): at android.widget.TextView.sendOnTextChanged(TextView.java:6131)
12-22 13:08:17.640: ERROR/AndroidRuntime(1077): at android.widget.TextView.setText(TextView.java:2691)
12-22 13:08:17.640: ERROR/AndroidRuntime(1077): at android.widget.TextView.setText(TextView.java:2556)
12-22 13:08:17.640: ERROR/AndroidRuntime(1077): at android.widget.EditText.setText(EditText.java:75)
12-22 13:08:17.640: ERROR/AndroidRuntime(1077): at android.widget.TextView.setText(TextView.java:2531)
12-22 13:08:17.640: ERROR/AndroidRuntime(1077): at com.project.TaxCalculator.GSTAct
So whats the wrong with this ? Why i am not able to get effect for both the EditText ? Thanks.