0

I want to show data of recent bookings of a user from firebase database in a recycler view. I have tried this, but it doesn't work.

final String id = FirebaseAuth.getInstance().getCurrentUser().getUid();
    DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference("Bookings");
    DatabaseReference dateRef = rootRef.child(id);

    ValueEventListener eventListener = new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            for(DataSnapshot dSnapshot : dataSnapshot.getChildren()) {
                for(DataSnapshot ds : dSnapshot.getChildren()) {
                    String Ftour =  ds.child("Tour").getValue(String.class);
                    String FPeople = ds.child("TotalPeople").getValue(String.class);
                    String FPrice =  ds.child("TotalPrice").getValue(String.class);
                   Log.d("TAG", Ftour + " / " + FPeople + " / "+ FPrice);

                    listD.add(new RHolder(Ftour,FPeople,FPrice));
                }
            }
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {}
    };
    dateRef.addListenerForSingleValueEvent(eventListener);

And my database is this:

Database Image Here

I want TotalPeople TotalPrice and Tour to be shown in Recyclerview

4
  • why didn't it work? are you getting an runtime error or is the output wrong?
    – Yuca
    Aug 10, 2018 at 17:15
  • when i open it, it goes back to previously open page automatically Aug 10, 2018 at 17:25
  • I think it not related to firebase. It look working for me. Please check it in your code maybe you have call 'finish()' somewhere in adapter or activity/fragment that related to this screen
    – JustKhit
    Aug 10, 2018 at 18:40
  • now it is not closing automatically but it doesn't shows any data into recyclerview Aug 11, 2018 at 12:23

1 Answer 1

0

As far as I can tell your code is not handling the Recent level that you have in your JSON. If that is indeed the cause of the problem you describe, you can fix it with:

dateRef.child("Recent").addListenerForSingleValueEvent(eventListener);
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.