I am having issues with addTextChangedListener. I have 2 edittext (edittext1 and edittext2) that when the text (in this case numbers) are added or changed I need it to run a calculation and output it to a textview called resultstext.
I have found many examples and have modified them to do what I need them to do, but when I call the editText1.addTextChangedListener.inputTextwatcher;
it tells me it cant find the symbol addTextChangedListener
. Below is the code, how to straighten this out?
package com.example.MyProject;
import android.os.Bundle;
import android.app.Activity;
import android.text.Editable;
import android.view.FocusFinder;
import android.view.Menu;
import android.widget.EditText;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
private android.widget.EditText editText1;
private android.widget.EditText editText2;
private android.widget.TextView resultsText;
private void onItemSelected() {
editText1 = (EditText)findViewById(R.id.textView13);
editText2 = (EditText)findViewById(R.id.textView15);
resultsText = (android.widget.TextView)findViewById(R.id.textView16);
}
android.text.TextWatcher inputTextWatcher = new android.text.TextWatcher()
{
public void afterTextChanged(android.text.Editable s) {
calculateResult();
}
public void beforeTextChanged(CharSequence s, int start, int count, int after){}
public void onTextChanged(CharSequence s, int start, int before, int count){}
};
editText1.addTextChangedListener.inputTextWatcher;
editText2.addTextChangedListener.inputTextWatcher;
private void calculateResult() throws NumberFormatException {
Editable editableValue1 = editText1.getText(),
editableValue2 = editText2.getText();
double value1 = 0.0,
value2 = 0.0,
result;
if (editableValue1 != null)
value1 = Double.parseDouble(editableValue1.toString());
if (editableValue2 != null)
value2 = Double.parseDouble(editableValue2.toString());
result = ((0.5 * value1) / 6.1) * value2;
resultsText.setText(String.valueOf(result));
}
}