I want to empty an EditText
based on a timer, according to the following behaviour:
At time
t1
, the user starts typing. TheEditText
should be cleared at timet1
+ 10 seconds.Once the
EditText
has been cleared, the timer should stop.When the user types in it again, at time
t2
, the field should be cleared att2
+ 10 seconds, and so forth.
I tried using a Handler
in the afterTextChanged
method in the TextChangedListener
.
However, this is not giving the desired behaviour: the Handler
is started when the user starts to type but from then on, it keeps clearing the text every 10 seconds, even when the user hasn't typed anything (which seems obvious from the way I have coded).
But I do not know how I can change it so that the text gets clears after 10 seconds from when the user starts typing something, rather than every 10 seconds non-stop.
Isn't there a way to use a Timer
, that's better than using Handlers
? Handlers
seem like a thread running in parallel once triggered.