【发布时间】:2016-05-23 16:02:49
【问题描述】:
我有一个列表视图数据来自服务器并显示在列表视图中。我希望每 10 秒刷新一次列表视图,我该怎么做,这是我的列表视图代码。
protected void showList() {
try {
JSONObject jsonObj = new JSONObject(myJSON);
peoples = jsonObj.getJSONArray(TAG_RESULTS);
for (int i = 0; i < peoples.length(); i++) {
JSONObject c = peoples.getJSONObject(i);
String data = c.getString(TAG_DATA);
final String dataaaa = rcdata.getText().toString().trim();
HashMap<String, String> user_data = new HashMap<String, String>();
user_data.put(TAG_DATA, data);
personList.add(user_data);
}
ListAdapter adapter = new SimpleAdapter(
DataSendActivity.this, personList, R.layout.layout_chat,
new String[]{TAG_DATA},
new int[]{R.id.data}
);
list.setAdapter(adapter);
} catch (JSONException e) {
e.printStackTrace();
}
}
【问题讨论】:
-
如果你只想在 10 秒内更新它而不管服务器发送的数据如何,使用 Timer.scheduleAtFixedRate()
-
如何使用请告诉我我是android新手
-
您也可以使用 CountDownTimer。启动定时器10秒,将更新后的arrayList传给Adapter,在adapter上执行notifySetDataChange。
标签: android listview android-studio refresh