I know a little bit about TextWatcher
but that fires on every character you enter. I want a listener that fires whenever the user finishes editing. Is it possible? Also in TextWatcher
I get an instance of Editable
but I need an instance of EditText
. How do I get that?
EDIT: the second question is more important. Please answer that.
TextWatcher
didn't work for me as it kept firing for everyEditText
and messing up each others values.Here is my solution:
Hence by using the
getChildAt(xx)
method you can retrieve any item in theListView
and get the individual item usingfindViewById
. And it will then give the most recent value.First, you can see if the user finished editing the text if the
EditText
loses focus or if the user presses the done button (this depends on your implementation and on what fits the best for you). Second, you can't get anEditText
instance within theTextWatcher
only if you have declared theEditText
as an instance object. Even though you shouldn't edit theEditText
within theTextWatcher
because it is not safe.EDIT:
To be able to get the
EditText
instance into yourTextWatcher
implementation, you should try something like this:Note that the above sample might have some errors but I just wanted to show you an example.
I have done it using
AutotextView
:As far as I can think bout it, there's only two ways you can do it. How can you know the user has finished writing a word? Either on focus lost, or clicking on an "ok" button. There's no way on my mind you can know the user pressed the last character...
So call
onFocusChange(View v, boolean hasFocus)
or add a button and a click listener to it.Anyone using ButterKnife. You can use like: