I am using firebase ListenerForSingleValueEvent and trying to get a list of Address class and put them into an arraylist but this thing is not working.. i tried to call a function or something but it didnt work
mDatabase.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot postSnapshot: dataSnapshot.child("addresses").getChildren()) {
Adress adress = new Adress(postSnapshot.getValue(Adress.class));
adresses.add(adress);
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
I have no idea how to solve it and i didnt find anyone has the same problem as me
Please help,Thanks
edit1: the problem is i cant add the address class to the arraylist using anything
it's just like i cant do it inside the listener, i checked that everything is ok .. also when i check the adresses arraylist size inside the lister it increases then out of the listener it returns to 0.. like the adresses.add function worked only at the listener itself or something like that