我想将数据从Firebase加载到arraylist,但似乎无法正常工作。以下是我的代码和Firebase屏幕截图。它返回一个空的arraylist。 al2是arraylist:
void getstops(int IDs){
String url = "https://bus-tracking-5ba3a.firebaseio.com/Route-Stops/";
mDatabase2 = FirebaseDatabase.getInstance().getReferenceFromUrl(url);
ValueEventListener vel = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot data : dataSnapshot.getChildren()){
al2.add(data.getValue().toString());
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
};
mDatabase2.child(Integer.toString(IDs)).addListenerForSingleValueEvent(vel);