UI Not Updating in Android

I was trying to setVisibility of the UI elements in Android but it just won' t update then I realized that the Activity is running on a separate thread.

The only way to update the UI is to put the code inside the UI thread like OnCreate(), OnStart(), OnResume etc. Apparently I have a callback functions outside the thread that needs to update the UI when the callback is invoked.

There are other workaround for this but it just messes up the code.

Handler to the rescue!

So here is an easy way to implement this..

- First Define your handler

Handler updateUI;


- In OnCreate method:



The way to call this in your Method:



That's it!

コメント

人気の投稿