解决了。
有两个地方需要改。public Cursor getAllCostData() {
SQLiteDatabase database = getWritableDatabase();
return database.query("imooc_daily", null, null, null, null, null, "cost_date" +"ASC");
}最后面的排序需要改成 "cost_date ASC"
if (cursor != null) {
while (cursor.moveToNext()) {
CostBean costBean = new CostBean();
costBean.costTitle = cursor.getString(cursor.getColumnIndex("cost_title"));
costBean.costDate = cursor.getString(cursor.getColumnIndex("cost_date"));
costBean.costMoney = cursor.getString(cursor.getColumnIndex("cost_money"));
mCostBeanList.add(costBean);
}
cursor.close();
}这里获取不了cost_money的准确列数,所以需要改成如下形式。
if (cursor != null) {
while (cursor.moveToNext()) {
CostBean costBean = new CostBean();
int dataColumnIndex = cursor.getColumnIndex("cost_title");
costBean.costTitle = cursor.getString(dataColumnIndex + 0);
costBean.costDate = cursor.getString(dataColumnIndex + 1);
costBean.costMoney = cursor.getString(dataColumnIndex + 2);
mCostBeanList.add(costBean);
}
cursor.close();
}这里是以cost_title为基准列数,向后退出cost_date和cost_money的列数。