A simple and effective solution with Kotlin
Extend EditText :
fun EditText.onSubmit(func: () -> Unit) { setOnEditorActionListener { _, actionId, _ -> if (actionId == EditorInfo.IME_ACTION_DONE) { func() } true } }
Then use the new method as follows:
editText.onSubmit { submit() }
Where submit() looks something like this:
fun submit() {
More general extension
fun EditText.on(actionId: Int, func: () -> Unit) { setOnEditorActionListener { _, receivedActionId, _ -> if (actionId == receivedActionId) { func() } true } }
And then you can use it to listen to your event:
email.on(EditorInfo.IME_ACTION_NEXT, { confirm() })
Francesco Donzello Feb 15 '18 at 15:03 2018-02-15 15:03
source share