본문 바로가기

Kotlin/안드로이드 공부

editText 텍스트 변경 감지

728x90

editText.addTextChangedListener(object: TextWatcher{
override fun afterTextChanged(s: Editable?) {
val str = s.toString()
inputBtn.isEnabled = str.isNotEmpty()
}

override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
// TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}

override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
// TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}

 

 

첫 줄처럼 editText에 addTextChangedListener 달아주고

오버라이딩만 하면됨!

이렇게 간단한 건데 뭐 하나 할때마다 찾아서 하고 있다.