How To Use Timer-threads And Views
My problem is: I wrote a little android app, which uses many ImageViews. Their Images have to be changed in the code. So far it worked fine, but I wanted to add kind of algorithm s
Solution 1:
Use a handler. Timer task runs on a different thread. So you cannot update ui from it. You should update ui on the main UI Thread. You can either use a handler or runonuithread inside the timer tak run method to update ui. But i would suggest you to use a handler
Handler m_handler;
Runnable m_handlerTask ;
m_handler = newHandler();
m_handlerTask = newRunnable()
{
@Overridepublicvoidrun() {
// do something
m_handler.postDelayed(m_handlerTask, 1000); // instad of 1000 mention the delay in milliseconds
}
};
m_handlerTask.run();
Or use
runOnUiThread(newRunnable(){
@Overridepublicvoidrun(){
//update ui here
}
});
Post a Comment for "How To Use Timer-threads And Views"