Update ListView in the main thread from another thread

前端 未结 6 806
北恋
北恋 2020-12-08 08:34

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().

6条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-08 09:18

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

    Invoke adapter.notifyDataSetChanged() in onPostExecute(...) method.

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

提交回复
热议问题