I have a list in java android:
List<FirebaseData> GetListMap(String data){
final List<FirebaseData> Elements = new ArrayList<>();
FirebaseDatabase database = FirebaseDatabase.getInstance();
mShiftReference = database.getReference("Map/Data/").child(data);
mListener = mShiftReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot child: dataSnapshot.getChildren()) {
Elements.add(child.getValue(FirebaseData.class));
}
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
// Failed to read value
Log.w("data", "Failed to read value.", error.toException());
}
});
return Elements;
}
When i try to exctract the size of the array it returns 0, for example:
int size = GetListMap("2019-06-24").size();
Or i can't exctract any property.
Any idea what i'm doing wrong.
GetListMapreturns aList<FirebaseData>, but you're assigning its result to anint. What's actually going on? (And this looks like it's adding a listener for when a change happens later, but it's not actually clear whether you've waited for the change to happen.)int size = GetListMap("2019-06-24").size();