安卓更新用户界面
基本上现在我显示一个加载屏幕(loading.setVisibility(View.VISIBLE);
),然后使用“BufferedReader”加载一些外部数据,然后隐藏加载屏幕(loading .setVisibility(View.INVISIBLE);
) 之后。问题是加载屏幕永远不会显示。代码都在正确的位置,GUI 只是直到方法结束才更新,而此时显然为时已晚,因为加载屏幕再次设置为不可见。
有没有什么方法可以在方法中强制更新 UI?
任何帮助将不胜感激!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果不使用后台线程就无法做到这一点。在 Android 上可以通过多种方法执行此操作,但最简单的方法是使用 AsyncTask
值得阅读 Painless threading 了解更多信息。
希望这有帮助,
菲尔·莱洛
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
我认为,你应该阅读 Android 中的 AsyncTask 类,然后看看这个例子:
http://labs.makemachine.net/2010/05/android-asynctask-示例/
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/