nil*_*ash 2 android listview baseadapter notifydatasetchanged
我正在开发一个Android应用程序,其中我使用一个基本适配器并以列表形式显示数据.现在发生了什么如果我从列表中删除任何对象,如果我打电话notifyDataSetChanged,它没有按预期工作.我按照以下方式尝试了这个.
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
shareDataList = getData();
shareListAdapter = new SharedHistoryListAdapter(this, shareDataList);
sharedList.setAdapter(shareListAdapter);
}
@Override
protected void onResume()
{
super.onResume();
// after deleting data it is coming inside onresume ...
shareDataList = getData();
shareListAdapter.notifyDataSetChanged();
}
Run Code Online (Sandbox Code Playgroud)
我检查了我的活动内部和适配器内部的数据大小.所以在活动中它显示了预期的计数,但在适配器内它没有显示更新的计数.我错过了什么吗?需要一些帮助.
将列表设置为适配器后,无法更改列表的引用.所以删除该行
shareDataList = getData();
Run Code Online (Sandbox Code Playgroud)
并替换为
shareDataList.clear();
shareDataList.addAll(getData());
Run Code Online (Sandbox Code Playgroud)
现在调用 shareListAdapter.notifyDataSetChanged();
| 归档时间: |
|
| 查看次数: |
2518 次 |
| 最近记录: |