在Android中清空ArrayList

时间:2013-07-11 01:15:58

标签: android arraylist

我正在从arrayList保存记录,每当我回到我使用该arrayList并保存另一条记录的活动时,前一条记录也与新记录一起保存。我怎样才能清空arrayList?

  ArrayList<String> arraySubBrand = new ArrayList<String>();
    for (int j=0; j<checkSelected.length; j++)  {
        if(checkSelected[j]==true) {
            String values = BrandListAdapter.mListItems.get(j);
            Cursor rSubBrand = databaseHandler.getReport_SubBrandCode(values);
            if(rSubBrand.moveToFirst()) {
                SubBrandCode = rSubBrand.getString(rSubBrand.getColumnIndex(Constants.SUBBRAND_CODE));
            }
            arraySubBrand.clear();
            arraySubBrand.add(SubBrandCode);

            String subBrand = arraySubBrand.toString();
            subBrand = subBrand.replace("[", "");
            subBrand = subBrand.replace("]", "");

            databaseHandler.SaveSubBrand(new Cons_iReport (ReportCode, subBrand));
        }                       
    } 

1 个答案:

答案 0 :(得分:1)

试试ArrayList.clear() 它会清空您的ArrayList