How to DELETE data from FIREBASE database from Sketchware app?

If you have an app which displays data from firebase database in a custom ListView, and you want to delete data from it, then follow this method.

This method of deleting data is for apps which push data to firebase database on button click by using blocks as shown in image below,
retrieves data from firebase database, on Firebase DB onChildAdded event, by using blocks as shown in image below,

In order to delete data from this kind of app follow the steps given below.

1. Add a new String list str.

2. In the CustomView, add an ImageView imageview2 and set it's image to delete icon. On clicking this ImageView the item will get deleted.



3. In Firebase DB onChildAdded event, inside Firebase DB... get children to List Map... then block,
add the block
Add [childKey] to List String [str],
as shown in image below.

This will create a list of keys or children at the DatabaseReference 'Chat'.

4. In the event onBindCustomView add the block
When [imageview2] clicked,
Inside this use blocks to delete key at that position in FirebaseDB and delete data at that position in String list:
FirebaseDB Chat delete key [get at (position) of List String (str)],
delete at (position) of List str.

If the app is using Firebase Storage to store images and push the url of images to FirebaseDB using blocks as shown below,


Then to delete the image alongwith the message, in onBindCustomView, inside When imageview2 clicked, alongwith the blocks shown above, use following blocks:
If (ListMap [map1] contains at (position) key [image]) then,
FirebaseStorage [fstore] delete file url (get value at (position) key [image] of ListMap [map1])

5. Add a new event Firebase DB onChildRemoved and there add the blocks to retrieve data from Firebase to MapList and display it in ListView, as shown in image below.

6. Save and run the project. Wait for the app to load data from firebase database. After that if you click inageview2 at any position in the list, data at that position in database will get deleted.

Watch the video below:


Comments

  1. Thank you.. so much...
    i hope more tutorials to come

    ReplyDelete
  2. Cara ini berhasil untuk menghapus tetapi untuk aplikasi saya yang terhapus malah list bagian yang paling atas/pertama

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. Hi, thanks for this website,
    Thus, when I try to implement this, I get an error compiling :
    Listview1Adapter cannot be resolved to a type.
    Where am I wrong?
    Thanks

    ReplyDelete
    Replies
    1. My solution is here http://www.sketchwarehelp.com/2017/10/how-to-create-custom-listview-in.html

      Delete
  5. Maybe you have not added listview1 onBindCustomView event.

    ReplyDelete
  6. I have implemented firebase for my app using topics I found here. I can add and delete records, but I really like to figure out how to update a record. Does anyone have an example on how to do this?

    ReplyDelete
  7. How to save ,reterive and edit the data to firebase.simply, not in listview.means to say data is fixed in numbers(not unlimited)

    ReplyDelete
  8. You can follow this
    https://youtu.be/DIMjofO8Yt0

    and this
    http://www.sketchwarehelp.com/2018/03/check-for-latest-app-version-using.html?m=1

    to understand how to edit data in Sketchware.

    ReplyDelete
    Replies
    1. I tried your video about using firebase on name, english , science and such. It was doing great at first. But when I tried to save the data, it will not publish on the main xml, I cannot view the display custom. Please help me how to fix it.

      Delete
  9. sanjeev, i am working on app Water Quality Results. I want to show result when user enter an id. The result will retrieve/fetch from firebase database. Please help me.

    ReplyDelete
  10. Greetings all.
    I'm developping an app but i'm facing a problem with user data.
    I'm using firebase and i wish to know how one user's datab is differentiated from another. Because i'm afraid when users will edit the data to database from the app, one user's info will delete another.
    I'm asking this because I want my app to have client space in such a way that each client has his personal infos! Help please

    ReplyDelete
  11. How to Retrieve customer details using customer id from firebase database.

    ReplyDelete
  12. Hi. My app view error when i click on the delete icon. Error message:
    Invalid list operation: Invalid index 14, size is 0.
    I dont have a sending images.

    ReplyDelete
  13. Hello how can i fix it. I get invalidlist operation
    :Invalid endex, 0 size is 0

    ReplyDelete
  14. Dear sir, if i create an app and login through firebase. And i wany to show users Name on the screen.
    How can I fetch users name from firebase of particular users??
    Please solve this .. i got stuck over here.

    ReplyDelete
  15. Storage uri cannot contains a path element ??

    ReplyDelete
  16. i got this error from Firebase DB component : Error Code = 3, Error Messages = Permisiion Denied...

    I already set the database console to allow everyone to read/write

    ReplyDelete

Post a Comment

Popular posts from this blog

A Flash Light App in Sketchware

Create Music Player app in Sketchware

In Sketchware: How to create a calculator for any simple formula?

Simple car racing android game in Sketchware

Firebase auth in Sketchware for Login Activity