2012-04-12 7 views
0

Ich entwickle eine einfache Listview, aber ich erhalte eine falsche Information und nicht eine korrekte Datenform db.Korrigieren Sie die Ansicht Ausstellung auf Android

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> 

Das Ergebnis hiervon ist: [email protected] und der richtige Wert muss das Wort „Allgemein“ sein.

Was ist los?

danke im voraus.

Antwort

0

ich entdeckte, was falsch war. Ich habe vergessen, toString in meiner Klasse zu überschreiben.

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

Ich hop, dass es anderen Menschen helfen kann.

0

Versuchen Sie, diese

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()); 
    } 
} 
Verwandte Themen