I am trying to add a value from onDataChanged method inside a for loop. each time whenever for loops is getting executed then the value will be added to the arraylist. now my problem is i cannot return that arraylist. it is showing null object.
ArrayList<BookingRequest> bookedSlot;
BookingRequest currRequet;
req.orderByChild("b_id").equalTo("01").addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
currRequet = snapshot.getValue(BookingRequest.class); // you
bookedSlot.add(snapshot.getValue(BookingRequest.class));
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}