我想記錄一個數組列表的內容。 arraylist包含一個具有4個參數的自定義對象。當我執行下面的代碼時,我得到以下日誌。我想是的[姓名,班級,三十九十],[姓名,班級,三十九十]等問題logging arraylist
自定義對象類的字符串:
public class Data {
String NAME;
String CLASS;
String THIRTY;//this is the thirty day supply
String NINETY;//this is the ninety day supply
public Data(){
super();
}
public Data(String NAME, String CLASS, String THIRTY, String NINETY){
super();
this.NAME = NAME;
this.CLASS = CLASS;
this.THIRTY = THIRTY;
this.NINETY = NINETY;
}
}
活動:
ArrayList<Data> array = new ArrayList<Data>();
Cursor c = mDBHelper.getReadableDatabase().query(Constants.K_Table, null, Constants.Name +"=?", new String[] {SEARCH}, null, null, null);
startManagingCursor(c);
if (c.moveToFirst()){
NAME = c.getString(c.getColumnIndex(Constants.Name));
CLASS = c.getString(c.getColumnIndex(Constants.Class));
THIRTY = c.getString(c.getColumnIndex(Constants.Month));
NINETY = c.getString(c.getColumnIndex(Constants.Three_Month));
array.add(new DrugData(NAME, CLASS, THIRTY, NINETY));
Log.d(TAG, "array contains: "+ array.toArray().toString());
}while(c.moveToNext());
日誌:
01-28 22:31:44.742: D/Activity(23656): the array contains: [[email protected]]
感謝狀,偉大工程!優秀的解釋 – benbeel 2012-01-29 16:04:01