2 weimingyu weimingyu_ 于 2016.09.07 15:51 提问

遍历数据库,如果数据很多这个arraylist是不是会崩啊!要怎么解决啊?

//遍历所有账单 private void selectAll(){ List list=new ArrayList(); ListDBAdapter adapter=new ListDBAdapter(this,list); listView.setAdapter(adapter); //数据库的列数 int count=dbUtil.select().getColumnCount(); //获得的数据库游标 Cursor c=dbUtil.select(); while (c.moveToNext()){ OrderHistory history=new OrderHistory(); for (int i = 0; i < count; i++) { history.set_id(c.getInt(0)); history.setPay_number(c.getString(1)); history.setAmount_paid(c.getDouble(2)); history.setTaam(c.getDouble(3)); history.setOrder_amount(c.getDouble(4)); history.setBilling_method(c.getInt(5)); history.setBilling_number(c.getString(6)); history.setDate(c.getString(7)); history.setTimestamp(c.getLong(8)); history.setPayee(c.getString(9)); history.setIntegral(c.getInt(10)); history.setIs_sync(c.getInt(11)); history.setPay_state(c.getInt(12)); history.setIs_print(c.getInt(13)); history.setMonth(c.getInt(14)); history.setDay(c.getInt(15)); } list.add(history); }

2个回答

caozhy
caozhy   Ds   Rxr 2016.09.08 04:18

看你多到什么程度,几万条几十万条肯定不会,最多就是消耗的内存多一些吧。

buquan4041
buquan4041   2016.09.18 08:26

不会,不过你也需要注意数据库的优化。

Csdn user default icon
上传中...
上传图片
插入图片