I have a cursor that contains the results of a query which returns the a list of ingredient names and their corresponding measurements from an SQLite database.
I am trying to implement a function that will deduct these values from another table when a button is pressed.
I am having some trouble trying to implement this function using the cursor values. Can I just pass the cursor into the function or should I be putting the cursor into a list and then passing the list variables into the function?
Below is the code I have so far but if anyone can point me in the right direction that would be great.
Cursor
final Cursor ingredients = adapter.getRecipesIngredients(recipeCode);
getRecipeIngredients Function
public Cursor getRecipesIngredients(int code)
{
return db.rawQuery("select _id, ingredient_name, measurement from ingredients where recipe_code = " + code, null);
}
Button code with function
Button cookButton = (Button) findViewById(R.id.cookButton);
cookButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
while (ingredients.moveToNext())
{
//how should I be passing the cursor into the fucntion?
adapter.deductIngredient(ingredients);
}
}
});
SQL function to update table
//deducting ingredients after cooking
public boolean deductIngredient(String ingredient, int measurement)
{
db.rawQuery("update kitchen set kitchen.measurement = kitchen.measurement - "+measurement+" where kitchen.ingredient_name = "+ingredient, null);
return true;
}
Aucun commentaire:
Enregistrer un commentaire