i am trying to add the keys from a firebase database to an arraylist in my onDataChange method.
mDatabase = FirebaseDatabase.getInstance().getReference("events");
mDatabase.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if(dataSnapshot.exists()) {
for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
String event = snapshot.getKey();
Log.d("did it work??", event);
eventList.add(event);
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
when i log event it'll print but its not adding to eventList arrayList
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…