无法在日志中显示数组列表

Cant display arraylist in logs

大家好,我从 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

编辑:

Class 卡片

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;
}

}

您需要在 Cards class 中覆盖 toString() 以产生您想要的输出。

示例:

@Override
public String toString() {
    return String.format("id:%d name:%s code:%s value:%s country:%s",
            id, name, code, value, country);
}