Search for same ingredient and add them

Hello App-Inventors,

I have the following blocks:

I want to create a shopping list, where all the ingredients are listed.
Before, a function should check each meal (like "Kartoffelsuppe", "Erbsensuppe" ... ) if there exists same ingredients like "Wasser" and add them together.

The result should shown as a list like:

  • Kartoffeln: 500 Gramm
  • Erbsen: 775 Gramm
  • Möhren: 375 Gramm
  • Wasser: 4 Liter

I am thinking about it for a whole week and tested around but don't get it ...

Do you have any idea?

could you provide the aia doc? so we can see if we could help you

There it is:

Meal_creation.aia (37.2 KB)

On Screen1 there is a list with all the meals available.
Button "Gericht hinzufügen" go to screen "AddMeal".

On "AddMeal" I want to create a new meal (at this point only with three ingredients).
First txt-box is for the name of the meal,
second for ingredient 1 followed by the amount and the list picker is for the unit (e.g.: "Erbsen" "500" "Gramm").
The same goes for ingredient 2 and 3.
After clicking the button "Hinzufügen" the meal with its ingredients is inserted to the database.

Screen "Testscreen" is for .. jeah creating the aboved described situation and then implementing it in addMeals Screen ...

Some of the blocks are there just for testing around. Some blocks are not final ...

The greater txt-box and the list-view are just understanding for me and securing that it is doing what I want. (^.^).

This type of problem works better with tables (lists of lists) and a group by sum procedure similar to the SQL SELECT SUM GROUP By construct.

This sample app groups and sums expenses, as opposed to grouping and summing ingredients, but the base concept is the same.

group_sum.aia (7.6 KB)

Here is a raw data Comma Separated Values (CSV) file...

When the file arrives from the Media folder, it gets scrubbed and split into 4 columns.

This procedure can be used to summarize column 4 by column 3:

Note that I had to remove a header row to avoid trying to sum header text.

The procedures:

P.S. These blocks can be dragged directly into your Blocks Editor workspace.

as @ABG already mentioned, this could be done much easier with tables...
and let me add, why not using the built in SQLite database to easily create, filter and join tables?
see my sqlite extension here App Inventor Extensions: SQlite | Pura Vida Apps to access the database
note: there are also other sqlite extensions available...

your query to get the receipt for Kartofelsuppe could look like this
SELECT ingredients FROM receipts WHERE receiptname = "Kartoffelsuppe"


Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by icon24 Taifun.

Thanks for the help. I'll give it a try.

I just stumble over the CSV ... you have 4 colums, each row there have one value - I don't get it how it will do for more values, like:
Meal_One, ingredient_1, ingredient_2, ingredient_3 [...], amount_ingredient_1, amount_ingredient_2 [...] and so on.
There are meals with just 2 ingredients and meals with 10+ ingredients.
I want to prepare some meals as a standard, but it will also be fully costumizable: the user can add own meals with his own ingredients. And in that case maybe water as an ingredient will not be at the same place in the list ...

Thank you for your tipps.

You say there is a built-in SQLite database? Which of the storage items I should choose then? I did'nt find it or am I just blind? Or I don't understand it ...

Although thanks for your extensions. I bought the billing extension already. :wink:

This sounds like a parts explosion problem.

Some sample reading on how to structure your data ...

the SQlite databae is available on all Android devices, also Android itself is using it...
unfortunately there is no built in sqlite component available, you have to use an extension to work with it...