0

我在这里从我的代码中获取对象数据,但我不知道我该怎么做。

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_manage);

    Log.d(TAG, "onCreate");

    datasource = new DataSource(this);
    datasource.open();

    List<Encouragement> values = datasource.getAllEncouragements();

    Log.d(TAG, "values");

    ArrayAdapter<Encouragement> adapter = new ArrayAdapter<Encouragement>(this,
        android.R.layout.simple_list_item_1, values);

    setListAdapter(adapter);
    Log.d(TAG, "end of onCreate");
}

public List<Encouragement> getAllEncouragements() {

    List<Encouragement> encouragements = new ArrayList<Encouragement>();

    Cursor cursor = database.query(DatabaseHelper.TABLE_ENCOURAGEMENTS,
            allColumns, null, null, null, null, null);

    cursor.moveToFirst();

    while (!cursor.isAfterLast()) {
        Encouragement encouragement = cursorToEncouragement(cursor);
        encouragements.add(encouragement);
        cursor.moveToNext();
    }

    cursor.close();
    return encouragements;
}

正在列表项中生成com.example.myActivity.myObject@34563475

4

1 回答 1

1

listview 正在调用toString()以表示 myObject。您没有覆盖该方法,因此调用toString()了默认方法。Object.toString()

@Override
public String toString(){
   return this.name; // whatever you need to represent this instance of myObject.
}
于 2013-04-05T15:52:14.130 回答