when adding the data to the list it's fine but after calling the method getNotes the list is empty
the snapshot gets the data correctly and data added to the list correctly but after that when passing the list to the mutableLiveData the list return null. how to solve this?
public class NotesViewModel extends ViewModel {
public static List<UserNote> notesList = new ArrayList<>();
DatabaseReference databaseNotesReference = FirebaseDatabase.getInstance().getReference("USERNOTES").child(Variables.uId);
MutableLiveData<List<UserNote>> mutableLiveData = new MutableLiveData<>();
public void getModelNotes(){
getNotes();
mutableLiveData.setValue(notesList);
}
private void getNotes(){
databaseNotesReference.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {
UserNote userNote = dataSnapshot.getValue(UserNote.class);
notesList.add(userNote);
}
@Override
public void onChildChanged(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {
UserNote userNote = dataSnapshot.getValue(UserNote.class);
notesList.add(userNote);
}
});
};
}