How do I know when my edit text is done being edited? Like when the user selects the next box, or presses the done button on the soft keyboard.
I want to know this so I can clamp the input. It looks like text watcher's afterTextChanged happens after each character is entered. I need to do some calculations with the input, so I would like to avoid doing the calculation after each character is entered.
thanks
Using an EditText object xml defined like this:
We can capture its text i) when the user clicks the Done button on the soft keyboard (OnEditorActionListener) or ii) when the EditText has lost the user focus (OnFocusChangeListener) which now is on another EditText:
This works for me. You can hide the soft keyboard after made the calculations using a code like this:
Edit: added return values to onEditorAction
EditText
inheritssetOnFocusChangeListener
which takes an implementation ofOnFocusChangeListener
.Implement
onFocusChange
and there's a boolean parameter forhasFocus
. When this is false, you've lost focus to another control.EDIT
To handle both cases - edit text losing focus OR user clicks "done" button - create a single method that gets called from both listeners.
By using something like this
To be more highlevel you may use TextWatcher's afterTextChanged() method.
I have done this simple thing, when focus is shifted from edit text get the text. This will work if user shifts the focus to select other views like a button or other EditText or any view.