Skip to content Skip to sidebar Skip to footer

How Can I Remove Specific Item From List When Data In Firebase Realtime Db Is Removed?

When a data in realtime database is removed, I want to remove the data from list as well. I wrote following code, but it does not work. Is there anybody can help me? @Over

Solution 1:

You will need to keep the keys of the TODO items from the database in onChildAdded. Then when onChildRemoved gets called, you can look up the position of the item by its key and remove it from the todoItems list based on its position.

So in onChildAdded:

todoItems.add(todoItem);
todoItemKeys.add(dataSnapshot.getKey());

And then in onChildRemoved:

intindex = todoItemKeys.indexOf(dataSnapshot.getKey());
todoItems.remove(index);
todoItemKeys.remove(index);

Post a Comment for "How Can I Remove Specific Item From List When Data In Firebase Realtime Db Is Removed?"