mercredi 8 avril 2015

How do I have multiple entries for my SQLite recipe table?

complete Android newbie here. So I was making a recipe database for my class, and I want a "Search By Ingredient" option for the app. However, when my listview pulls all the ingredients from the DB, they are not individual, but clumped together based on recipe.


Here is my code for the DB:



String sql = "CREATE TABLE IF NOT EXISTS recipe (" +
"_id INTEGER PRIMARY KEY AUTOINCREMENT, " +
"Name TEXT, " +
"Ingredients TEXT, " +
"Recipe TEXT )";
db.execSQL(sql);


//This is the content for the Recipes. AKA the database
ContentValues values = new ContentValues();

values.put("Name", "Baked Eggcado");
values.put("Ingredients",
"Avacado" +
"Egg" +
"Salt" +
"Pepper");

values.put("Recipe",
"\n" +
"Prep Time: 5 minutes\n" +
"\n" +
"Cook Time: 15 to 20 minutes\n" +
"\n" +
"Total Time: 25 minutes\n" +
"\n" +
"Servings: 1\n" +
"\n" +
"Ingredients:\n" +
"\n" +
"1 avocado\n" +
"\n" +
"1 egg\n" +
"\n" +
"Salt and pepper to taste\n" +
"\n" +
"Directions:\n" +
"\n" +
"1. Preheat oven to 425°F.\n" +
"\n" +
"2. Slice avocado in half.\n" +
"\n" +
"3. Scoop out pit to create hole for the egg.\n" +
"\n" +
"4. Place avocado in a small baking cup. Line with tinfoil for minimal clean­up.\n" +
"\n" +
"5. Crack the egg into the hole.\n" +
"\n" +
"6. Bake for 15 to ­20 minutes.\n" +
"\n" +
"7. Season with salt and pepper, or seasoning of your choice. If you have them, sprinkle \n" +
"\n" +
"chopped scallions on top");
db.insert("recipe", "Name", values);


So my Question is, how do I get the listview to show "Avacado", "Egg", "Salt", & "Pepper" individually instead of all in one cell. Thanks for any help!


Aucun commentaire:

Enregistrer un commentaire