ともちゃんのアプリ開発日記

組込みC言語プログラマだったともちゃんが、四苦八苦しながら、AndroidのJAVA/Kotlin、iOSのSwiftUIを習得して行きます。ともちゃんの備忘録も兼ねています。

EditTextの入力の変化を検出する

TextWatcherを使います。

1.TextWatcherの登録

// 年のTextWatcherを設定
edTextYear.addTextChangedListener(new textWatcherYearMonthDate());

2.TextWatcher本体

// 年月日のTextWatcher本体
public class textWatcherYearMonthDate implements TextWatcher {

// テキスト変更後
public void afterTextChanged(Editable s) {
(ここに処理を入れる)
}

// テキスト変更前
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}

// テキスト変更後
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
}