0

我正在从 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));
        }                       
    } 
4

1 回答 1

1

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

于 2013-07-11T01:34:50.357 回答