mardi 3 novembre 2020

How does one get a random children of a Firebase node

My goal was to get a random Question object from the "Videos" node to later display it, and as there's no builtin support for querying a random child I have to get a random Object myself, from that iterator, somehow.

   videoArrayList=new ArrayList<>();

        DatabaseReference reb= FirebaseDatabase.getInstance().getReference("Videos");
        reb.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(@NonNull DataSnapshot dataSnapshot)
            {

                for (DataSnapshot ds:dataSnapshot.getChildren())
                {
                    ModelVideo modelVideo=ds.getValue(ModelVideo.class);
                    videoArrayList.add(modelVideo);

                }
                adapterVideo=new AdapterVideo(VideosActivity.this,videoArrayList);
                videosRv.setAdapter(adapterVideo);


            }
});



Aucun commentaire:

Enregistrer un commentaire