Helllo伙计们,我从SQLite数据库创建了 arraylist ,当我尝试在日志中显示这个arraylist时:
01-05 18:57:50.238 16099-16099/com.testdymamicalarray I/ARRAY﹕ com.testdymamicalarray.Cards@41777ae8
01-05 18:57:50.238 16099-16099/com.testdymamicalarray I/ARRAY﹕ com.testdymamicalarray.Cards@41777cb0
01-05 18:57:50.238 16099-16099/com.testdymamicalarray I/ARRAY﹕ com.testdymamicalarray.Cards@41777cd0
01-05 18:57:50.238 16099-16099/com.testdymamicalarray I/ARRAY﹕ com.testdymamicalarray.Cards@41777cf0
01-05 18:57:50.238 16099-16099/com.testdymamicalarray I/ARRAY﹕ com.testdymamicalarray.Cards@41777d10
01-05 18:57:50.238 16099-16099/com.testdymamicalarray I/ARRAY﹕ com.testdymamicalarray.Cards@41777d30
01-05 18:57:50.238 16099-16099/com.testdymamicalarray I/ARRAY﹕ com.testdymamicalarray.Cards@41777d50
01-05 18:57:50.238 16099-16099/com.testdymamicalarray I/ARRAY﹕ com.testdymamicalarray.Cards@41777d70
01-05 18:57:50.238 16099-16099/com.testdymamicalarray I/ARRAY﹕ com.testdymamicalarray.Cards@41777d90
01-05 18:57:50.238 16099-16099/com.testdymamicalarray I/ARRAY﹕ com.testdymamicalarray.Cards@41777db0
01-05 18:57:50.238 16099-16099/com.testdymamicalarray I/ARRAY﹕ com.testdymamicalarray.Cards@41777dd0
01-05 18:57:50.238 16099-16099/com.testdymamicalarray I/ARRAY﹕ com.testdymamicalarray.Cards@41777df0
01-05 18:57:50.238 16099-16099/com.testdymamicalarray I/ARRAY﹕ com.testdymamicalarray.Cards@41777e10
01-05 18:57:50.239 16099-16099/com.testdymamicalarray I/ARRAY﹕ com.testdymamicalarray.Cards@41777e90
01-05 18:57:50.239 16099-16099/com.testdymamicalarray I/ARRAY﹕ com.testdymamicalarray.Cards@41777eb0
01-05 18:57:50.239 16099-16099/com.testdymamicalarray I/ARRAY﹕ com.testdymamicalarray.Cards@41777ed0
01-05 18:57:50.239 16099-16099/com.testdymamicalarray I/ARRAY﹕ com.testdymamicalarray.Cards@41777ef0
01-05 18:57:50.239 16099-16099/com.testdymamicalarray I/ARRAY﹕ com.testdymamicalarray.Cards@41777f10
01-05 18:57:50.239 16099-16099/com.testdymamicalarray I/ARRAY﹕ com.testdymamicalarray.Cards@41777f30
为什么我没有看到 arraylist的值?
我在 MainActivity 中的代码:
List cards=dataBaseAdapter.getAllCards();
int a=cards.size();
for(int i=0;i<a;i++){
Log.i("ARRAY",cards.get(i).toString());
}
在 DBAdapter 中创建ArrayList的方法:
public List getAllCards(){
List cards = new ArrayList();
SQLiteDatabase sqLiteDatabase= helper.getWritableDatabase();
Cursor cursor=sqLiteDatabase.rawQuery(helper.QUERY,null);
cursor.moveToFirst();
while(!cursor.isAfterLast()){
Cards oneCard=parseCards(cursor);
cards.add(oneCard);
cursor.moveToNext();
}
cursor.close();
return cards;
}
请告诉我我做错了什么。我只想在日志中查看我的值,例如id,name,value,code,country
修改
班级卡片
public class Cards {
int id;
String name;
String code;
String value;
String country;
public Cards(int id, String name, String code, String value,String country) {
this.id = id;
this.name = name;
this.code = code;
this.value = value;
this.country = country;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public Cards(String name, String code, String value , String country) {
this.name = name;
this.code = code;
this.value = value;
this.country = country;
}
public Cards() {
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
}
答案 0 :(得分:2)
您需要覆盖toString()
课程中的Cards
以生成所需的输出。
示例:
@Override
public String toString() {
return String.format("id:%d name:%s code:%s value:%s country:%s",
id, name, code, value, country);
}