본문 바로가기

카테고리 없음

안드로이드 edittext ACTION_DONE 처리, TextWatcher

반응형

IME ActionDone 처리 

et.setOnEditorActionListener(object : TextView.OnEditorActionListener{
            override fun onEditorAction(v: TextView?, actionId: Int, event: KeyEvent?): Boolean {
                if (actionId == EditorInfo.IME_ACTION_DONE){

                    return true
                }
                return false
            }
        })

edittext layout xml 안에 

android:inputType="text"

android:imeOptions="actionDone"

를 넣어주고 

 if문 안에 원하는 동작 넣어주면 키보드 엔터 클릭시 원하는 동작을 실행한다


TextWatcher 

한 글자 한 글자 입력 받을 때 이벤트가 필요 할 때에는 텍스트와쳐를 사용한다 

et.addTextChangedListener(object :TextWatcher{
            override fun afterTextChanged(s: Editable?) {
              
            }
            override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
            }

            override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
            }
        })
반응형