addListenerForSingleValueEvent(new ValueEventListener()不起作用

时间:2018-02-18 23:16:57

标签: java android database firebase firebase-realtime-database

调试器显示程序进入循环但是专辑列表为空。 我不知道为什么?

    d=FirebaseDatabase.getInstance().getReference().child(ALBUMES);

    d.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            //clearing the previous artist list
            albums.clear();
            //iterating through all the nodes
            for (DataSnapshot postSnapshot : dataSnapshot.getChildren()) {
                //getting artist
                Album album = postSnapshot.getValue(Album.class);
                //adding artist to the list
                albums.add(album);
            }
            //creating adapter
            AlbumsLista albumAdapter = new AlbumsLista(getActivity(), albums);
            //attaching adapter to the listview
            listViewAlbums.setAdapter(albumAdapter);
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });
    Log.d(TAG, "albums:"+ albums.size());
}

0 个答案:

没有答案