0
我想從數據庫中獲取實際項目,但我的方法似乎正在返回路徑。任何幫助都感激不盡。Android數據庫返回到項目而不是實際項目的路徑
方法來獲取所有產品:
// Getting All Products
public List<Product> getAllProducts() {
List<Product> productList = new ArrayList<Product>();
// Select All Query
String selectQuery = "SELECT * FROM " + TABLE_PRODUCT;
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
// looping through all rows and adding to list
if (cursor.moveToFirst()) {
do {
Product product = new Product();
product.setId(Integer.parseInt(cursor.getString(0)));
product.setName(cursor.getString(1));
product.setImage(cursor.getString(2));
product.setPrice(cursor.getFloat(3));
// Adding product to list
productList.add(product);
} while (cursor.moveToNext());
}
// return product list
return productList;
}
我的陣列適配器:
products = db.getAllProducts();
adapter = new ArrayAdapter<Product>(MainPage.this, android.R.layout.simple_list_item_1, products);
productList.setAdapter(adapter);
這是它是如何恢復成列表視圖: 「com.handy.shoppy.Product @ 43e9578「
謝謝。