hello there, can anyone help me what's wrong with my code here. I did delete tap but I'm still not sure if the coding is correct or not. However , the problem here is that my total calories does not updated after delete hmm
counter_calories3.aia (16.2 KB)
Show your relevant blocks.
What do you mean by "delete tap" ? Reset or Delete an Item (notifier)
(post deleted)
Please show your block to get what you want.
I opened the aia and prepared a blocks image for the OP:
The ListView Delete option is hampered by the way it is forced to parse those fancy Elements in the ListView to get the number of calories in that Element.
Look how complicated each Element is:
Your split at '-' won't get you the total kcal for that Element:
It doesn't even give you a number, and you did not try to follow up by decreasing the stored total. (not that it would have been a good idea, compared to recalculating from the new consumption table described below.)
This kind of app requires keeping the calorie consumption in a table (list of lists).
It would have these columns:
- food name
- calories per unit
- qty
- total kcal for this food
That table can be processed into fancy looking elements for a listView in a separate pass. Because the Elements will be in the same order as the original table, using the ListView SelectionIndex for the remove list item from the consumption table makes it easy to reformat the ListView and recalculate the total calories for the consumption table.
It is overcomplicated to keep the total kcal in a separate counter.
You should be recalculating it from the consumption table by looping over its rows and keeping a running total of item 4 of each row.
Redundant data is a recipe for error.
By the way, unless your user is an easily bored gourmet who has sworn to never eat the same food twice in his lifetime, the app would benefit from keeping the food menu separate from the consumption table:
Food data base TinyDBFoods (Namespace='foods')
tag: food name (i.e. Coca Cola, 1 ounce)
value: calories per unit of that food
Consumption data base TinyDBConsumption (Namespace='consumption')
tag: food name (same as in food data base)
value: number of units consumed for that food (default 0)
You would keep the food data base and add to it as you encounter new foods.
You would clear the consumption data base nightly.
If you are tracking long term, add weekly and monthly consumption data bases.
Thanks for the suggestions! I’ll separate the food info and consumption data into different tables (TinyDBFoods
and TinyDBConsumption
) and recalculate the total calories dynamically. I’ll try again with these changes!
hello, I'm beginner, I want to ask ,what if I don't want to use a table for the list view and just want to use regular text instead? Do I really need to use a table to make it easier ?
You don't have to show every list or table on the screen if you don't need to.
You can keep them temporarily in global variables to help you loop through them to build up totals and subtotals
But when a task requires associating pieces of data together, you will need internal data structures like lists, tables, and dictionaries.
You can tell you need those when you see the word 'of' in the problem statement.
Will the owner of a blue Chrysler 200 please go to the parking lot? Your car is being towed.
You could reformat your table into YAML format, to make it fit into a single ListView.
Sample: