Deleting item from list view and tinyDB

Hey guys, I'm new here but I couldn't find a solution in any online tutorials that seemed to work. I am creating an app that has a panic button to send out a messege to a list that they can create. The button is on the first screen and I have the functionality working for it but I am having trouble getting the hand of listview and tinydb.

The second screen is the configure screen where you can create the contact list for the panic button.
I can enter names and numbers into the list and display them in the listview but I can't figure out how to delete them from the listview and the database. everytime i think i got it right i hit my update list to refresh and the whole list shows up again.

Could someone look at my code and tell me what I messed up? I use the tag number for the panic button and name&number to display on the listview. I want to be able to hit the delete button and have it delete the item I select on the listview and remove that name and number from the tinyDB as well. Also can someone verify that my erase database is correct?

Welcome to the community @steven_county

First of all, when the delete button is clicked, show the list view to select which contact to delete.
Thereafter, in the list viewer's after picking event, remove the selected item from the list.

(I am not able to figure out in which tag you have store the list, so just modify the code accordingly)

I'm getting an error with this when I try to touch an item in the listview. To clarify a little bit. I am using the tag "name&number" to store the info I want to display on the listview. I also store just the phone number in a tag called " number" which is the tag I use on the panic button to pull the entire list of numbers to send out the emergency text to.

My database erase button is not right either, when I click it, it removes the list view but the moment I add a new name and number the old list appears along with the new name and number

  • In Screen's initialize event, set global list == tinydb tag- name&number.
    Because everytime you are resetting the list by just doing add item to list to an empty list and storing it back in TinyDB.

  • Change all your ElementsFromString to Elements.

still getting an error, I noticed in your code that its trying to remove the item when i touch the listview item. I have a delete button setup to do the actual delete that I want to use so that i can select the item then click the delete.

also thank you for responding so quickly to help me

1 Like

image

I don't see any other problem, could you share the error message?

I did it the other way round, so no probs, you can change it your way.

I just typed a bunch of jibberish into the name and number so don't mind that. this is the error i get when i try to touch an item in the listview

error

And this is what it shows on my phone when I'm testing it

I guess because you have only 1 item

I have never tried removing list item with only 1 item in list

Try this ......

ok ill check that right now

Try this .... Slightly ammended

Test.aia (3.2 KB)

You dont need the UPDATE LIST button. I have block coded it to auto update the list when the contact is added. Similarly for the DELETE CONTACT - You simply SELECT the contact in the List View to DELETE. you can ammend the blocks, to activate the DELETE CONTACT button, if desired.

ok I did the code but when updated the database all my old stuff appeared in there and I got an error, I believe it might be from old stuff stored on there. How do I clear the entire database and start from scratch? like if you were to format a hard drive
I tried new users named one, two, and three. all those showing up in the error are from previous testing.

1 Like

This is what my erase button looks like but it doesn't seem to clear the database
erase

just delete everything in tinyDB using clear all
or store the new values under a different tag

This should CLEAR it all......

thats what i thought too but i added the clear tag one as well cause it wasn't working. im getting a bad argument error when i try to delete

1 Like

Check your code ....