Home:ALL Converter>Display EditText value in another TextView after edit

Display EditText value in another TextView after edit

Ask Time:2012-12-28T03:21:43         Author:onepiece

Json Formatter

I have an EditText where the user inputs a string. After edit, the string is displayed in a TextView. I created a custom class called TextValidator which implements TextWatcher, to satisfy the parameters of the addTextChangedListener(TextWatcher watcher) method. When I run it, the moment I press a letter to input into the editText, the app crashes.

In the MainActivity:

EditText editText1 = (EditText)findViewById(R.id.editText1);
editText1.addTextChangedListener(new TextValidator((EditText)findViewById(R.id.editText1)));

In my TextValidator class:

public class TextValidator extends Activity implements TextWatcher {
    private EditText editText;

    public TextValidator(EditText editText) {
        this.editText = editText;
    }

    public void validate(TextView textView, String text)
    {
        //I want to later check the string for valid format
    }

    final public void afterTextChanged(Editable s) {
        ((EditText)findViewById(R.id.textView1)).setText(editText.getText().toString());
        //validate(textView, text);
    }

Author:onepiece,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/14060070/display-edittext-value-in-another-textview-after-edit
yy