APP Bird APP Bird - 6 months ago 16
Android Question

retrive data from firebase

I'm new to android developing. I tried retrieving data from firebase. which worked . but I'm unable to filter unique identifier from database results .

FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference myref = database.getReference("user_foods");
myref.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Log.d("foods",dataSnapshot.getValue().toString());
}

@Override
public void onCancelled(DatabaseError databaseError) {

}
});


results are like


XsgGhY7qUY5Qa3t8 = {food = apple} , ..... etc


I want to remove that unique identifier & just display results as


Apple , Mango ...etc


thank you

Answer

I figured the answer. If anyone has same issue use "child event listener "

 FirebaseDatabase database = FirebaseDatabase.getInstance();
    DatabaseReference myref = database.getReference("user_foods");
    myref.addChildEventListener(new ChildEventListener() {
        @Override
        public void onChildAdded(DataSnapshot dataSnapshot, String s) {
            Log.d("foods",dataSnapshot.getValue().toString());

        }

        @Override
        public void onChildChanged(DataSnapshot dataSnapshot, String s) {

        }

        @Override
        public void onChildRemoved(DataSnapshot dataSnapshot) {

        }

        @Override
        public void onChildMoved(DataSnapshot dataSnapshot, String s) {

        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });
Comments