Search code examples
androidkotlintextviewanko

Kotlin addTextChangeListener lambda?


How do you build a lambda expression for the EditText addTextChangeListener in Kotlin? Below gives an error:

passwordEditText.addTextChangedListener { charSequence  ->
    try {
        password = charSequence.toString()
    } catch (error: Throwable) {
        raise(error)
    }
}

Solution

  • This looks neat:

    passwordEditText.setOnEditorActionListener { 
        textView, keyCode, keyEvent ->
        val DONE = 6
    
        if (keyCode == DONE) {                       
             // your code here
        }
        false
    }