Search code examples
androidfirebase-realtime-databaseandroid-recyclerviewfirebaseui

Firebase UI recycler view adapter onDataChanged get reference to the data that changed


Im using firebase ui recyclerview adapter, as I understand it, when the acivity starts onDataChanged is called and then for every subsequent change in the database it is called again, what I want to do is check every child the first time onDataChanged is called and then only check the child that changed the next time it is called, so I was thinking I could set a boolean to tell the system if its the first time or not, but how can I after that only check the child that changed?


Solution

  • That's what the onChildChanged method is for. 😁 It'll do exactly what you want:

    @Override
    public void onChildChanged(@NonNull ChangeEventType type,
                               @NonNull DataSnapshot snapshot,
                               int newIndex,
                               int oldIndex) {
        super.onChildChanged(type, snapshot, newIndex, oldIndex);
        MyData data = getItem(newIndex);
        // Do something
    }