Android: Update Listview after Thread loads data from the net

后端 未结 3 1709
小蘑菇
小蘑菇 2020-12-24 15:01
  1. I like that my GUI appears immediately when the user starts the app.
  2. Then some data (text, pictures) gets loaded in the background (like YouTube app).
3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-24 15:54

    Just found it myself while reading this thread and trying around.

    Short: AsyncTask's method onProgressUpdate can touch the view: http://developer.android.com/reference/android/os/AsyncTask.html#onProgressUpdate(Progress...)

    Background: I needed to call requery on my cursor so a ListView kept being updated while the task fills the database. The requery call made in doInBackground failed with the mentioned CalledFromWrongThreadException but same code in onProgressUpdate works.

提交回复
热议问题