我有一个带SimpleAdapter的ListView。 ListView的数据来自Sqlite。我想在查询结果为空时删除所有listview项。 如何使用SimpleAdapter删除listview所有项目?
SimpleAdapter adapter;
ArrayList<HashMap<String, String>> urunsorgu_liste;
Veritabani db = new Veritabani(getActivity().getApplicationContext());//My database class
urunsorgu_liste =db.sorgu(sehirSp, urunSp);
if(urunsorgu_liste.size()==0)// if query result is empty
{
Toast.makeText(getActivity(), "Query is epty", Toast.LENGTH_SHORT).show();
// ??????
}
else{
List<HashMap<String, String>> sorguMaps = new ArrayList<HashMap<String, String>>();
urun_idler = new int[urunsorgu_liste.size()];
for(int i=0;i<urunsorgu_liste.size();i++){
HashMap<String, String> map = new HashMap<String, String>();
String ad=urunsorgu_liste.get(i).get("urun_adi");
String etiket=urunsorgu_liste.get(i).get("urun_etiket");
String fiyat=urunsorgu_liste.get(i).get("urun_fiyat");
String sehir=urunsorgu_liste.get(i).get("urun_sehir");
urun_idler[i] =Integer.parseInt(urunsorgu_liste.get(i).get("id"));
map.put("ADI",ad);
map.put("ETIKETI",etiket);
map.put("FIYATI",fiyat);
map.put("SEHRI", sehir);
sorguMaps.add(map);
adapter = new SimpleAdapter(getActivity(), sorguMaps, R.layout.sorgu_fragment_list_item, from, to);
listV.setAdapter(adapter);
}