В моем дневнике рецептов у меня есть 3 класса, Recipe.class:
public Recipe(String title, String firstImage, String secondImage, String thirdImage, String instructions, int targetPeople, int time, int calories, ArrayList<Ingredient> ingredients, ArrayList<Tag> tags) {
this.title = title;
this.firstImage = firstImage;
this.secondImage = secondImage;
this.thirdImage = thirdImage;
this.instructions = instructions;
this.targetPeople = targetPeople;
this.time = time;
this.calories = calories;
this.ingredients = ingredients;
this.tags = tags;
}
Ingredient.class:
public Ingredient(String ingredient_name, int quantity) {
this.ingredient_name = ingredient_name;
this.quantity = quantity;
}
и Tag.class:
public Tag(String tag_name) {
this.tag_name = tag_name;
}
Когда я сохраняю новый рецепт, я использую два цикла для хранения тегов и ингредиентов, и каждый из них добавляется в соответствующий список ArrayList <> (чтобы связать больше ингредиентов и тегов с одним и тем же рецептом) следующим образом:
for (int c=0; c < countTags; c++) {
childChipView = (Chip) chipTagGroup.getChildAt(c);
childTextViewTag = childChipView.findViewById(R.id.chip_item);
childTag = childTextViewTag.getText().toString();
newTag = new Tag(childTag);
dbHelper.insertTag(newTag);
tags.add(newTag);
}
// ingredients fields settings
for (int d=0; d<countIngredients; d++) {
childViewIng = parentIngredientLayout.getChildAt(d);
childTextViewI = childViewIng.findViewById(R.id.ingredientsField);
childTextViewQ = childViewIng.findViewById(R.id.quantityField);
childIngredient = childTextViewI.getText().toString();
childQuantity = Integer.parseInt(childTextViewQ.getText().toString());
newIngredient = new Ingredient(childIngredient, childQuantity);
dbHelper.insertIngredient(newIngredient);
ingredients.add(newIngredient);
}
После этого я сохраняю в трех соответствующих таблицах моей БД (RECIPE_TABLE, INGREDIENT_TABLE, TAG_TABLE). Моя проблема в том, как я могу сохранить два ArrayLists <> внутри RECIPE_TABLE ? Я хочу, то есть в той же строке этой таблицы, название, инструкции, время, калории и т. Д., А также два ArrayLists