0

単純なリストビューを開発していますが、間違った情報を受け取り、正しいデータ フォーム データベースではありません。

List<Category> values = cdao.listAllItems();
ArrayAdapter<Category> adapter = new ArrayAdapter<Category>(this,
   R.layout.row, values);
setListAdapter(adapter);


public List<Category> listAllItems() {
    List<Category> list = new ArrayList<Category>();

    Cursor cursor = db.rawQuery("SELECT _id, category " +
            " FROM category", null);

    while (cursor.moveToNext()) {
        Category c = new Category();
        c.setId(cursor.getInt(cursor.getColumnIndex("_id")));
        c.setCategory(cursor.getString(cursor.getColumnIndex("category")));
        list.add(c);
        Log.d(wallet.utils.Constants.TAG, c.getCategory());
    }
    return list;
}


<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="10dp"
    android:textSize="16sp" >
</TextView>

この結果は wallet.entity.Category@44dbe038 となり、正しい値は「General」という単語である必要があります。

なにが問題ですか?

前もって感謝します。

4

2 に答える 2

0

私は何が間違っているかを発見しました。クラスで toString をオーバーライドするのを忘れていました。

@Override
public String toString() {
    return category;
}

それが他の人を助けることができることを願っています。

于 2012-04-17T17:04:06.713 に答える
0

これを試して

if(cursor.getCount > 0) {
   cursor.moveToFirst();
   for(int i =0;i<cursor.getCount();i++) {
       Category c = new Category();
       c.setId(cursor.getInt(cursor.getColumnIndex("_id")));
       c.setCategory(cursor.getString(cursor.getColumnIndex("category")));
       list.add(c);
       Log.d(wallet.utils.Constants.TAG, c.getCategory());
   }
} 
于 2012-04-12T23:38:34.637 に答える