erasing EditText and EditView in Android

This is linked to a previous post:
My layout is like this:

INPUT TEXT (EditText)

BUTTON

OUTPUT TEXT (TextView)

Task:
When the user enters an input & upon button click the output text appears.
I have to make sure I make the input & output disappear some 10 seconds after the button click(and after the output text appears).

Now, I cannot add a “TextWatcher” on TextView.
Initially I tried to use Handler on inputText which can have a TextWatcher. But somehow the Handler keeps running all the time in the background & I cannot “cancel” it.

So I switched to using timers. I used a method in the button onCick() method:

And after 10 seconds I would like to call timer.cancel() ( yet don’t know where!!)
As you can see the problem is that I obtain an error complaining that only UI threads can alter views. How can do this ?

Thanks

I would use Handler class. You can easily post delayed code & cancel it. It will run in correct Thread. Also, you can add TextWatcher or OnFocusChangeListener to detect & cancel text erasing when a user starts editing text again.