I have an imageView and want it to work like this:
ImageViewer visible
5 second pause
image view invisible
5 second pause
ImageViewer visible
and so on …
How do I do that? I have tried sleep but it freezes the whole program in 5 seconds. I just want to affect my imageView.
I’m not an Android programmer, but, as a general advice, I’d say you should perform the sleep, better said the waiting, on another thread and execute at the end of the waiting period, on the main thread, a method that toggles the visibility of your imageview.
Getting into more specific detail, I’d say you must use a Handler object because you cannot update most UI objects while in a separate thread. When you send a message to the Handler it will get saved into a queue and get executed by the UI thread as soon as possible:
or, a snippet of a shorter version,
using the
postDelayedmethod, that incorporates the delay within the message posting logic.