Viswa Sundhar
Viswa Sundhar

Reputation: 305

How to retrieve data from firebase with the key value?

{-KVsGKFs_VfPKYNylmH0={entryDate=11/14/2016, markerColor=30, daysSick=2, userId=ABCD, sickness=Flu, severity=Medium, longitude=-75.57221984863281, latitude=38.38811111450195, type=Viral}, 
15fKhOQizabN0EL6ZAq7SOk3Gqb2={entryDate=11/8/2016, markerColor=210, daysSick=5, userId=15fKhOQizabN0EL6ZAq7SOk3Gqb2, sickness=Pneumonia, severity=High, longitude=-77.1867304, latitude=38.80375897, type=Bacterial}, 
2SfN7GkHsjXHFuGGYQJAQoRCOho1={-KXLF4gT9wUfvgRuYxWI={entryDate=11/24/2016, markerColor=210, daysSick=3, userId=2SfN7GkHsjXHFuGGYQJAQoRCOho1, sickness=Anthrax, severity=Medium, longitude=0, latitude=0, type=Bacterial}}

For the following above json response i have to retrieve the data for all the key values of "sickness". How to retrieve it?

Upvotes: 0

Views: 207

Answers (1)

Jayamurugan
Jayamurugan

Reputation: 532

The below code would help you in getting all the key values from database... Here BTChild Details is a POJO class

databaseRef.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot snapshot) {
            BTLog.d(TAG, "There are " + snapshot.getChildrenCount() + " blog posts");
for (DataSnapshot postSnapshot : snapshot.getChildren()) {
                BTChildDetails post =postSnapshot.getValue(BTChildDetails.class);
                BTChildDetails btChildDetails = new BTChildDetails(post.getName(), post.getId(), false);
                childList.add(childDetails);
            }
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
            BTLog.d(TAG, "The read failed: ");
        }
    });

Upvotes: 1

Related Questions