Android - 无论如何在 doInBackground 中调用notifyDataSetChanged
我需要更新 AsyncTask 的 doInBackground 中的数百条记录。我想每 10 条记录更新一次列表视图。但是我们不能在doInBackground中调用notifyDataSetChanged。那么有没有办法在doInBackground中调用notifyDataSetChanged呢?
我正在考虑注册一个广播接收器。当doInBackground中每完成10条记录时,我们发送一个Intent,并且BroadcastReceiver中会调用notifyDataSetChanged?有什么建议吗?
I need to updating hundred of records in doInBackground of AsyncTask. I want to update my listview at each 10 records. But we cannot call notifyDataSetChanged in doInBackground. So there are anyway to call notifyDataSetChanged in doInBackground?
I'm thinking about register a BroadcastReceiver. We send an Intent when finish each 10 records in doInBackground and notifyDataSetChanged will be called in BroadcastReceiver? Any suggestion?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这正是 onProgressUpdate 的用途 - 更新 UI (通常是几次)在任务执行期间。您应该通知那里的适配器。
That's exactly what onProgressUpdate is for - updating the UI (usually several times) during the task execution. You should notify the adapter there.
protected void onProgressUpdate(Integer...values) {
_asyncTaskRunner.taskProgressUpdate();
}
示例
protected void onProgressUpdate(Integer... values) {
_asyncTaskRunner.taskProgressUpdate();
}
Meu examplo