본문 바로가기
Develop/android

textWatcher interface

by JmcH 2021. 8. 22.

editText에서 사용하는 리스너인 textWatcher 입니다.

변경될 수 있는 객체를 사용하면 textWatcher의 메소드가 변경하는 동작에 해당되는 객체를 호출해줍니다.

(3가지의 동작을 하나만 골라 사용하는 것이 아니고 모두 사용해야합니다.)

 

beforeTextChanged // text 입력 전 동작

onTextChanged // text 변경시 동작

afterTextChanged // text 입력이 종료된 후 동작

 

3개의 메소드는 거의 동시에 동작하기 때문에 로그를 찍어 확인하는 방법이 유용합니다.

textWatcher에 여러개의 editText를 사용할 경우 무한루프가 발생되기 때문에 removeTextChanged 를 사용하여 제거하거나

afterChanged에서 null체크를 해줍니다.

 

ex)

https://developer.android.com/reference/android/text/TextWatcher

 

TextWatcher  |  Android 개발자  |  Android Developers

 

developer.android.com

 

'Develop > android' 카테고리의 다른 글

layout setVisibility  (0) 2021.08.22
viewBinding (뷰 바인딩)  (0) 2021.08.22
코루틴 (coroutine)  (0) 2021.08.03
[Clone coding] instagram (3)  (0) 2021.07.09
[Clone coding] instagram (2)  (0) 2021.07.08