在Android Studio中存储和搜索字符串数据

我正在通过Android应用程序的开发来学习Java。我过去曾在python中玩过游戏,但java仍然相对较新-android应用程序开发也是如此,因此android studio也是如此。

我制作了一些较小的应用程序来计算游戏分数等,但是现在我正在尝试制作食谱应用程序,作为存储和搜索数据的练习。我想做的是在搜索视图中输入搜索字词,并从中返回基于以下内容的相关结果列表:标题,成分(猪肉,鸡肉,奶酪,土豆)或饮食限制(素食主义者,面筋)免费),具体取决于用户要搜索的选项。如有必要,可以为每个类别使用不同的搜索框。

我面临的问题是我非常不了解如何创建和操作该数据集。我目前的方法可以奏效,但如果重新复印的数量不多,那么维护起来将非常困难。

为表示自己的努力,以下是我到目前为止的工作: 为每个类别创建一个字符串数组:

标题:

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

成分:

    <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>

说明:

<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>

一旦我拥有所有这些字符串数组,我就使用索引号(必须相同,以防止交叉匹配的配方)来获取配方的每个不同信息集。

有人可以为我指出正确的方向,以便更统一,更容易维护这些数据吗?我设想将来会有几百种配方,因此希望能够使这些数据尽可能地可搜索。

mengduan_2009 回答:在Android Studio中存储和搜索字符串数据

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3164840.html

大家都在问