有人可以给我一个删除所有 ListView 项目并替换为新项目的示例代码吗?
我尝试更换适配器项目但没有成功。我的代码是
populateList(){
results //populated arraylist with strings
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, results);
listview.setAdapter(adapter);
adapter.notifyDataSetChanged();
listview.setOnItemClickListener(this);
}
// now populating list again
repopulateList(){
results1 //populated arraylist with strings
ArrayAdapter<String> adapter1 = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, results1);
listview.setAdapter(adapter1);
adapter1.notifyDataSetChanged();
listview.setOnItemClickListener(this);
}
这里repopulateList()
方法将添加到 ListView 项目,但它不会删除/替换所有 ListView 项目。