简体   繁体   中英

android: How to remove listview all items with SimpleAdapter

I have a ListView with a SimpleAdapter. The Data for the ListView comes from Sqlite.I want to remove the all the listview items when query result is empty. How to remove listview all items with SimpleAdapter ?

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);
        }

Used .clear() method of ArrayList

ArrayList.clear(From Java Doc ):

Removes all of the elements from this list. The list will be empty after this call returns

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM