【问题标题】:android: How to remove listview all items with SimpleAdapterandroid:如何使用 SimpleAdapter 删除 listview 所有项目
【发布时间】:2014-05-25 12:34:57
【问题描述】:

我有一个带有 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);
        }

【问题讨论】:

  • 刚刚用.clear()清除了你的ArrayList

标签: android sqlite listview android-listview


【解决方案1】:

使用.clear()的ArrayList方法

ArrayList.clear(来自Java Doc):

从此列表中删除所有元素。该列表将为空 此调用返回后

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-06-22
    • 1970-01-01
    • 2018-09-02
    • 2017-07-25
    • 1970-01-01
    • 2011-02-03
    • 1970-01-01
    相关资源
    最近更新 更多