Skip to content

Instantly share code, notes, and snippets.

@iscomad
Created March 26, 2021 07:50
Show Gist options
  • Save iscomad/b091a60d243bfdf83b6a240a0152eb41 to your computer and use it in GitHub Desktop.
Save iscomad/b091a60d243bfdf83b6a240a0152eb41 to your computer and use it in GitHub Desktop.
Helpful EditText extension functions
/**
* Triggers an action when user finishes editing
*/
fun EditText.doAfterTextEditingFinished(editingFinished: (String) -> Unit) {
var isEditing = false
doAfterTextChanged {
if (!isEditing && hasFocus()) {
isEditing = true
}
}
setOnFocusChangeListener { _, hasFocus ->
if (isEditing && !hasFocus) {
isEditing = false
editingFinished(text.toString())
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment