【发布时间】:2014-06-11 11:09:46
【问题描述】:
谁能解释一下为什么下面的代码不起作用? 每次用户使用以下代码单击刷新按钮时,我都会尝试更新我的报告列表
在updateReports(在所有的数据下载和解析之后):
reportsList = newReportsList;
listAdapter.notifyDataSetChanged();
以前在onCreateView:
listAdapter = new ReportsListAdapter(activity, R.layout.list_item_reports, reportsList);
listView.setAdapter(listAdapter);
但列表不会刷新并继续显示旧报告。我尝试使用listAdapter.clear() 和listAdapter.add() 使用for(我不能使用addAll,因为我需要使用API 10),但它给了我一个空指针异常。
有什么策略可以以最简洁的方式进行这种替换吗?
【问题讨论】:
标签: android android-listview listadapter