【发布时间】:2015-04-11 21:51:25
【问题描述】:
如何在日志中显示来自 ArraylList 的项目?
我有类 DataBaseAdapter,我有方法 getCardsArrayList,现在我想在日志中显示这个 ArrayLIst 中的每个项目
当我尝试在我的 MainActivity 中编写这些行时:
ArrayList<Cards> cards= dataBaseAdapter.getCardsArrayList();
for(int i=0; i<cards.size();i++){
Log.i("WORKS",cards[i]);
}
我有一个错误:Array type expected, found java.util.ArrayList<com.myproject.Cards>
卡片是我的带有getter和setter的类
DataBaseAdapter中的Arrayist:
public ArrayList<Cards> getCardsArrayList(){
SQLiteDatabase sqLiteDatabase= helper.getWritableDatabase();
Cursor cursor=sqLiteDatabase.rawQuery(helper.QUERY,null);
cursor.moveToFirst();
for (int i=0; i<cursor.getCount(); i ++){
cardsArrayList.add(new Cards(cursor.getString(0),cursor.getString(1),cursor.getString(2),cursor.getString(3)));
cursor.moveToNext();
}
return cardsArrayList;
}
【问题讨论】:
标签: android arraylist android-sqlite android-log