Android update UI

喜欢而已 提交于 2020-01-05 08:13:29

问题


Basically at the moment I'm showing a loading screen (loading.setVisibility(View.VISIBLE);) then loading some external data using a "BufferedReader" and then hiding the loading screen (loading.setVisibility(View.INVISIBLE);) afterwards. The problem is the loading screen is never shown. The code is all in the correct place the GUI just doesn't update until the end of the method when it is obviously too late because the loading screen is set to invisible again.

Is there any way to force update the UI mid way through a method?

Any help would be much appreciated!


回答1:


You can't do this without using a background thread. There are a number of ways you can do this on Android, but the simplest is to use AsyncTask

It's worth reading Painless threading for more information on this.

Hope this helps,

Phil Lello




回答2:


I think, you should read about AsyncTask class in Android, then take a look this example: http://labs.makemachine.net/2010/05/android-asynctask-example/



来源:https://stackoverflow.com/questions/5683164/android-update-ui

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!