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
    Replies
    1. It didn't work for me please help with the code.

      Delete
    2. Sir I have a doubt. If the user clears the data of the app then, the list string will be lost and we can't delete it anymore. Is there is an alternative way?

      Delete
  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. This comment has been removed by the author.

    ReplyDelete
  17. Hlo sir how clear database in one click in sketchwere. Help me plz

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

    ReplyDelete
  19. I'm getting an error. but i wrote same code as yours.

    my app automatically land on a page(main page) if the user is loggedin. since I'm logged in in my app, i automatically land on that specific page(main page). that page has a button that will load profile edit page when it is clicked.



    but when my app load that edit profile page, it automatically go back to that main page(main page). i cant even edit profile. and then after some seconds, my app crashed! after that it show a bug report

    how can i fix this? is there any way i can send you my error reault? please help.

    ReplyDelete
    Replies
    1. Ther is some bug in onCreate or onChildAdded or onBindCustomView of your Profile edit page. Check the first few lines of the bug report.

      Delete
    2. java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Stringjava.lang.Object.toString()' on a null object reference at (project name).EditProfileActivity$ListView1Adapter.getView(EditProfileActltivity.java:401)




      note: i have discovered that, when i load that editprofile page(with "add new" button and listview item are set (according to your video)) then it shows the custom listview data in a list without crushing . but if i have 2/3 list of data, then i have to scroll down to see all the list data below, and when i finish scrolling that page, and at the last point of list it goes back to main page and then app crushes!

      Delete
    3. this project is very important for me. I'm making a blood grouping database for my medical college which is very important for our college to make it easy for people to find and contact donor quickly. if you help me with some other way( getting my code and fix this problem) it will be so helpful

      Delete
    4. It crashes because the length of the 2/3 lists you are using are different. The different lists should have same number of data. Or use a single maplist.

      Delete
    5. i sent you an email. can you read that please?

      Delete
    6. hello, I'm from bangladesh. i study in a medical college. I'm making a blood grouping and donor find app. I've recenlty tried your code from "simple database app" a youtube video.but its getting crushed. my app has a landing page(main page) if user is loggedin. when i open my app it load the main page as I'm loggedin. that main page has a button(profile). this button load profile page which has one button(edit) and a list view to view edited data in profile page.

      main page(if loggedin otherwise
      app's landing page is login page)>>profile page(a "edit" button and list view)>>edit page(has a save button, some edittext fields)


      after installation when i go to that profile page since i haven't added any data to that listview, app automatically goes back to main page. i dont kbow how! but it takes some time may be 2/3 sec. if i can somehow manage to click that edit button and can save the edit text fields( blank) twice( very quickly, even black save)then 2 list data are saved,although app crushes, but when second time i run app and go to that profile page, it shows a list of my data. since i saved all the edittext fields as blank, and i somehow managed to save that type of blank data twice, the list shows two list data, one in the screen, and to see another list, i have to scroll down. but if i scroll and finished scrolling that list( at that specific time, when i just finish scrolling) app automatically goes back to main page. and then crushes!


      i think there's something when i finish scrolling, the list item may be set null! and then i get an error message!


      error message:

      java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Stringjava.lang.Object.toString()' on a null object reference at (project name).EditProfileActivity$ListView1Adapter.getView(EditProfileActltivity.java:401)


      hope you will help me. if you want i can send you my project through sketchware share link. please help

      Delete
  20. This comment has been removed by the author.

    ReplyDelete
  21. i want to load some data from firebase from a particular location like this:

    location(all users)
    ...-uid
    ........-details
    .............-name
    .............-city
    ..............-phone



    how can i load all users details in a custom listview? please help

    ReplyDelete
  22. dear sanjeev,
    one android developer told me,
    the apps we create using sketchware are counted as third party app(as we use third party app-sketchware). and every year google check if there's any third party app is play store. he also told me, all the third party apps create using sketchware or other 3rd party development tool will be deleted from play store by google.

    is this true? are the apps we create using sketchware counted as third party app? if so, will google remove apps created using sketchware?

    ReplyDelete
  23. Please I cant seem to find the "when view is clicked" block

    ReplyDelete

Post a Comment

Popular posts from this blog

Simple car racing android game in Sketchware

Creating a Drawing View in Sketchware

Enable Fullscreen for Youtube videos in WebView

How to enable upload from webview in Sketchware?

List of Calendar Format symbols valid in Sketchware