ユーザーが文字列を入力するEditTextがあります。編集後、文字列はTextViewに表示されます。addTextChangedListener(TextWatcher watcher)メソッドのパラメーターを満たすために、TextWatcherを実装するTextValidatorというカスタムクラスを作成しました。実行すると、文字を押してeditTextに入力すると、アプリがクラッシュします。
MainActivityの場合:
EditText editText1 = (EditText)findViewById(R.id.editText1);
editText1.addTextChangedListener(new TextValidator((EditText)findViewById(R.id.editText1)));
私のTextValidatorクラスでは:
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);
}