0

I'm trying to fetch the saved data from firebase, but the problem is that my code is fetching only the first field and not every field of data.

Here's what I am doing to fetch my data:

public void fetchDataFromFirebase() {
        retrieveRef = new Firebase("https://abc.firebaseio.com/data/");
        Query query = retrieveRef.orderByChild("postedOnDate");

        query.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                for (DataSnapshot postSnapshot : dataSnapshot.getChildren()) {
                    HRequests hRequests = postSnapshot.getValue(HRequests.class);
                    hDescription = hRequests.getHDescription();
                    hImage = hRequests.getHImage();
                    hLat = hRequests.getHLat();
                    hLng = hRequests.getHLng();
                    postedAtTime = hRequests.getPostedAtTime();
                    postedBy = hRequests.getPostedBy();
                    postedOnDate = hRequests.getPostedOnDate();

                    byte[] imageAsBytes = Base64.decode(homelessImage, Base64.DEFAULT);
                    bmp = BitmapFactory.decodeByteArray(imageAsBytes, 0, imageAsBytes.length);

                    Toast.makeText(getBaseContext(), "this got called", Toast.LENGTH_SHORT).show();

                }
            }

            @Override
            public void onCancelled(FirebaseError firebaseError) {
                Toast.makeText(getBaseContext(), firebaseError.getMessage(), Toast.LENGTH_SHORT).show();
            }
        });
    }

P.S.: I'm sure that I have 5-6 fields of data in my firebase database.

Please let me know how to fetch them all.

2
  • Without seeing the corresponding data structure (the JSON as text, not as a screenshot), it'll be difficult to help. I also see that you're storing images in the Firebase JSON database and looping over them, something that has been recommended against time-and-time again in the past months. Apr 27, 2016 at 14:21
  • What do you mean by first field? Do you mean the first child record?
    – dazza5000
    Apr 27, 2016 at 17:13

0

Your Answer

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