0

I am in the process of learning java through the development of android apps. I have in the past played in python but java is still relatively new - as is android app development and therefore android studio.

I've made some smaller apps that count game scores and the like but am now trying to make a cookbook app as an exercise in storing and searching data. What I'd like to do is to enter a search term into a searchview and from that return a list of relevant results based on things like: titles, ingredients (pork, chicken, cheese, potato), or dietary restrictions (vegan, gluten free) depending on which options the user wants to search through. I would be fine with a different search box for each category if necessary.

The problem I'm facing is that I am woefully ignorant of how to go about creating and manipulating this data set. My current approach can work but would be very difficult to maintain if the number of recopies was anything more than just a handful.

To show some effort on my end, here is what I have so far: create a string-array for each category:

Titles:

<string-array name="recipe_titles">
    <item> Clam Chowder </item> <!--> <!-->
    <item> Banana Bread </item> <!--> <!-->
    <item> Pancakes </item> <!--> <!-->
    <item> Corn Pudding </item> <!--> <!-->
</string-array>

Ingredients:

    <string-array name="ingredient_amount">
        <item>
\n"content here"
        </item> <!--> Clam Chowder <!-->
        <item>
\n"content here"
        </item> <!--> Banana Bread <!-->
        <item>
\n"content here"
        </item> <!--> Pancakes <!-->
        <item>
\nServing Size
\n(1 ½ qt. casserole)
\n
\n1 (14 ¾ oz) can Creamed Corn
\n1 (14 ¾ oz) can Whole Kernel Corn
\n3 Tbs. Flour
\n1 ½ tsp. Salt
\n4 Tbs. Butter, melted
\n4 Eggs
\n3 Tbs. Sugar
\n2 ½ c. ½ and ½
        </item> <!--> Corn Pudding <!-->
</string-array>

Instructions:

<string-array name="recipe_instructions">
    <item>
\n"content here"
    </item> <!--> Clam Chowder <!-->
    <item>
\n"content here"
    </item> <!--> Banana Bread <!-->
    <item>
\n"content here"
    </item> <!--> Pancakes <!-->
    <item>
\n1)    Butter a 1 ½ qt. casserole dish.
\n2)    Cream together the butter, sugar, and salt.
\n3)    Beat in the eggs until well blended.
\n4)    Add the flour and mix again.
\n5)    Stir in the corn and milk.
\n6)    Pour into the buttered casserole.
\n7)    Bake at 325 for 20 minutes and then stir.
\n8)    Bake for another 30-35 minutes or until the top is golden brown and a knife inserted into the middle comes out clean.

    </item> <!--> Corn Pudding <!-->
</string-array>

Once I have all those string arrays, I use the index number (which must be the same to prevent cross matching recipes) to get each different set of info for the recipe.

Can someone please point me in the right direction for a more cohesive and easier to maintain approach for this data? I envision having several hundred recipes down the road so the hope would be able to make this data as searchable as possible.

Jack Duane
  • 185
  • 3
  • 17
  • In the real world you would probably have a back-end database, and have API endpoints in back-end code to get the data into the app, and in the app keep the results cached in a SQLite db using Room. – Daniel Nugent Nov 04 '19 at 18:06
  • @DanielNugent thanks for the info. For a self taught programmer, is this something I can build towards or is it a little more complex than that? Alternatively, would there be a more "dumbed-down" version that would be simpler to make work, even if that meant I had to sacrifice some functionality? – Jack Duane Nov 04 '19 at 18:12
  • For something quick without a back-end, you could just use a pre-filled local SQLite database, see here for more info: https://stackoverflow.com/questions/513084/ship-an-application-with-a-database – Daniel Nugent Nov 05 '19 at 00:43

0 Answers0