2016-08-25 73 views
-1

這是我class databasehelper extends SQLiteOpenHelper如何從活動中獲得價值數據庫幫助者?

public List<Product>getListIndo(){ 
     Product product = null; 
     List<Product>productList = new ArrayList<>();`enter code here` 
     openDatabase(); 
     Cursor cursor = mDatabase.rawQuery("select * from product, null); 
     cursor.moveToFirst(); 
     while (!cursor.isAfterLast()){ 
      product = new Product(cursor.getInt(0),cursor.getString(1),cursor.getString(2),cursor.getString(3),cursor.getString(4),cursor.getString(5)); 
      productList.add(product); 
      cursor.moveToNext(); 
     } 
     cursor.close(); 
     closeDatabase(); 
     return productList; 
    } 
+0

將它作爲構造函數(或方法)參數傳遞。 – earthw0rmjim

回答

0

哪個值你想傳遞給databasehelper?您在您的sql查詢中使用select方法,這意味着從表product中檢索不插入的數據。如果將某些東西插入數據庫中,則必須使用INSERT INTO table_name