【发布时间】:2020-01-02 16:54:27
【问题描述】:
我使用 ListAdapter 在 Listview 中显示了一些数据。现在我希望列表视图在 x 秒后自动刷新。如何才能做到这一点? 我正在使用 AsyncTask 从服务器获取数据。
我试过这个:
public void reloadDeviceData() {
handler.postDelayed(runnable = new Runnable() {
public void run() {
new GetDevices().execute(); // this method will contain your almost-finished HTTP calls
handler.postDelayed(this, TIME);
}
}, TIME);
}
发生的事情是列表视图不刷新,而是在当前列表视图之后添加项目。 GetDevices 是这里扩展 AsyncTask 的类。
【问题讨论】:
-
你能把
GetDevices任务的代码贴出来吗? -
当你得到新数据时,你可以用你的adater设置notifydatasetchanged()
-
notifydatasetchanged() 是否实时检查数据?
-
是的......
-
使用 listview 不是 ggod 做法..请使用回收站视图
标签: android listview android-listview