从Firebase检索数据到arraylist

时间:2019-04-24 12:05:22

标签: java android firebase-realtime-database

enter image description here Firebase screenshot

我想将数据从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);

0 个答案:

没有答案