从另一个线程的主线程更新的ListView [英] Update ListView in the main thread from another thread

查看:463
本文介绍了从另一个线程的主线程更新的ListView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个单独的线程运行从互联网上获取数据。在那之后,我想通过调用adapter.notifyDataSetChanged更新在主线程中的ListView()。但是,这是行不通的。任何解决办法是什么?谢谢你。

I have a separate thread running to get data from the internet. After that, I would like to update the ListView in the main thread by calling adapter.notifyDataSetChanged(). But it does not work. Any workaround for that? Thanks.

推荐答案

使用AsyncTask的(<一href="http://developer.android.com/reference/android/os/AsyncTask.html">http://developer.android.com/reference/android/os/AsyncTask.html )。

Use AsyncTask ( http://developer.android.com/reference/android/os/AsyncTask.html ).

调用的 adapter.notifyDataSetChanged()的中的 onPostExecute(...)的方法。

有关详细信息,请阅读:<一href="http://android-developers.blogspot.com/2009/05/painless-threading.html">http://android-developers.blogspot.com/2009/05/painless-threading.html

For more details, please read this: http://android-developers.blogspot.com/2009/05/painless-threading.html

这篇关于从另一个线程的主线程更新的ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆