我试图从firebase获取保存的数据,但问题是我的代码只获取第一个字段而不是每个数据字段。
以下是我要取得的数据:
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。:我确定我的firebase数据库中有5-6个数据字段。
请让我知道如何获取所有内容。