0

我的 DatabaseHandler 类中有一个方法可以让您更新饮料(名称、类别、成分等),但我似乎无法让它工作。这是代码:

  // Updating single drink
  public int updateDrink(Drink drink) {
    SQLiteDatabase db = this.getWritableDatabase();

    ContentValues values = new ContentValues();
    values.put(KEY_NAME, drink.getName());
    values.put(KEY_CAT, drink.getCategory());
    values.put(KEY_IN1, drink.getIngredient1());
    values.put(KEY_IN2, drink.getIngredient2());
    values.put(KEY_IN3, drink.getIngredient3());
    values.put(KEY_IN4, drink.getIngredient4());
    values.put(KEY_IN5, drink.getIngredient5());
    values.put(KEY_IN6, drink.getIngredient6());
    values.put(KEY_TI1, drink.getTime1());
    values.put(KEY_TI2, drink.getTime2());
    values.put(KEY_TI3, drink.getTime3());
    values.put(KEY_TI4, drink.getTime4());
    values.put(KEY_TI5, drink.getTime5());
    values.put(KEY_TI6, drink.getTime6());

    // updating row
    return db.update(TABLE_DRINKS, values, KEY_ID + " = ?",
            new String[] { String.valueOf(drink.getID()) });
}

然后我在这里的活动中调用它:

db = new DatabaseHandler(order.this);

db.updateDrink(new Drink(drinkname.getText().toString(), 
    category.getText().toString(), 
    ing1.getText().toString(), 
    ing2.getText().toString(),
    ing3.getText().toString(), 
    ing4.getText().toString(), 
    ing5.getText().toString(), 
    ing6.getText().toString(), 
    Integer.parseInt(t1.getText().toString()), 
    Integer.parseInt(t2.getText().toString()), 
    Integer.parseInt(t3.getText().toString()),
    Integer.parseInt(t4.getText().toString()), 
    Integer.parseInt(t5.getText().toString()), 
    Integer.parseInt(t6.getText().toString())));
4

0 回答 0