Recover snapshot inside a node

Asked

Viewed 36 times

0

I need to retrieve all users within a user node, follow firebase structure:

inserir a descrição da imagem aqui

To recover these values I am making an addListenerForSingleValueEvent, follows code:

    private DatabaseReference firebaseRef;
    private DataSnapshot usuariosSnapshot;

firebaseRef = ConfiguracaoFirebase.getFirebase();

                //recuperar usuarios para criação do feed na hora da postagem
                DatabaseReference usuariosRef = firebaseRef
                        .child("usuarios");
                usuariosRef.addListenerForSingleValueEvent(new ValueEventListener() {
                    @Override
                    public void onDataChange(DataSnapshot dataSnapshot) {

                        usuariosSnapshot = dataSnapshot;

                    }

                    @Override
                    public void onCancelled(DatabaseError databaseError) {

                    }
                });

                postagemPendente.salvar(usuariosSnapshot);

even though the reference is pointing to the right place the users still shows as null, what I need to do to catch all these values from within the users node?

Note: All this inside an Adapter, which I find irrelevant but due to doubts.

1 answer

0


Try instead of DatabaseReference usuariosRef = firebaseRef.child("usuarios"); add .getReference().

getReference() gets the root node of the database. More information here.

So it would be DatabaseReference usuariosRef = firebaseRef.getReference().child("usuarios");

  • "firebaseRef = Configuracaofirebase.getFirebase();"on this line I already configure getReference

Browser other questions tagged

You are not signed in. Login or sign up in order to post.