访问其他DatabaseReference中的DatabaseReference

时间:2018-03-22 21:09:17

标签: android firebase-realtime-database

我想访问eventListener中的DatabaseReference速率到DatabaseReference a

 f =FirebaseDatabase.getInstance().getReference().child("a");

        ValueEventListener eventListener = new ValueEventListener() {
            @Override
            public void onDataChange(com.google.firebase.database.DataSnapshot dataSnapshot) {
                if (dataSnapshot.getChildren() == null) {
                    Toast.makeText(c, "no trucks", Toast.LENGTH_SHORT).show();

                    //Toast.makeText(this, "hi", Toast.LENGTH_SHORT).show();
                    //startActivity(new Intent(getActivity(), AdminHome2.class));
                }
                dogies.clear();

                for (com.google.firebase.database.DataSnapshot ds : dataSnapshot.getChildren()) {

                    d = new a();

                    d.setU(ds.getValue(a.class).getU());
                    Toast.makeText(c, d.getUid() + "", Toast.LENGTH_SHORT).show();
                    if (d.getU() != null) {
                    //////___________rate/
                    rate = FirebaseDatabase.getInstance().getReference().child("Rate").child(d.getU()).child("sum");

                        ValueEventListener eventListener2 = new ValueEventListener() {
                            @Override
                            public void onDataChange(com.google.firebase.database.DataSnapshot dataSnapshot) {
                                if (dataSnapshot.getChildren() == null) {
                                    Toast.makeText(c, "no rating", Toast.LENGTH_SHORT).show();

                                    //Toast.makeText(this, "hi", Toast.LENGTH_SHORT).show();
                                    //startActivity(new Intent(getActivity(), AdminHome2.class));
                                }

                                sumRate rate = new sumRate();
                                rate.setSum(dataSnapshot.getValue(sumRate.class).getSum());
                                rate.setNumCus(dataSnapshot.getValue(sumRate.class).getNumCus());
                                int a = rate.getSum();
                                int b = rate.getNumCus();
                                Toast.makeText(c, a + "", Toast.LENGTH_SHORT).show();
                                d.setNumCus(2);
                                d.setSumRate(2);

0 个答案:

没有答案