Recover Dynamic Childs on Firebase Android

Asked

Viewed 180 times

1

I have a structure on firebase as follows. In the client app when the person saves the information, creates a Child stored by the number entered in the cell field (creates Child with the person’s mobile number). If another person uses the app, when that other person saves (creates another Child with that new number that has been placed in the cell field). So we have two Children of different numbers.

How can I recover these values in my admin app, since Child will be dynamic.

Tenho dois numeros de teste no banco

This code below is where I retrieve the information and display in a Listview. If I put it like this databaseReference.child("Pedidos").child("(99)99999-9999") it searches in the bank and brings the information of that number, until then everything well, is working. However I am putting manually.

 databaseReference.child("Pedidos").addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {

            Pedido pd = new Pedido();

            listPedidosAdm.clear();

            for (DataSnapshot objSnapshot : dataSnapshot.getChildren()) {

                pd = objSnapshot.getValue(Pedido.class);
                listPedidosAdm.add(pd);
            }

            if (listPedidosAdm.size() <= 0) {
                Toast.makeText(AdmPedidosActivity.this, "Não há nenhum pedido",
                        Toast.LENGTH_SHORT).show();

            } else {

                AdapterPersonalizadoAdm adapter = new AdapterPersonalizadoAdm(listPedidosAdm,
                        AdmPedidosActivity.this);

                listview_AdmPedidos.setAdapter(adapter);

            }

        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });
}
  • 1

    pq you do not use the key as reference instead of the phone number?

No answers

Browser other questions tagged

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