答案 0 :(得分:0)
要显示特定日期的所有值,请使用以下代码:
DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
DatabaseReference ref = rootRef.child("Sreeauto").child("28-05-2018");
ValueEventListener valueEventListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot ds : dataSnapshot.getChildren()) {
String date = ds.child("date").getValue(String.class);
String incharge = ds.child("incharge").getValue(String.class);
String qty = ds.child("qty").getValue(String.class);
String shift = ds.child("shift").getValue(String.class);
Log.d("TAG", date + " / " + incharge + " / " + qty + " / " + shift);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {}
};
ref.addListenerForSingleValueEvent(valueEventListener);
输出将是:
28-5-2018 / Karthi / 500 / A Shift
要从所有日期获取这些值,请使用以下代码:
DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
DatabaseReference ref = rootRef.child("Sreeauto");
ValueEventListener valueEventListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot ds : dataSnapshot.getChildren()) {
for(DataSnapshot dSnapshot : ds.getChildren()) {
String date = dSnapshot.child("date").getValue(String.class);
String incharge = dSnapshot.child("incharge").getValue(String.class);
String qty = dSnapshot.child("qty").getValue(String.class);
String shift = dSnapshot.child("shift").getValue(String.class);
Log.d("TAG", date + " / " + incharge + " / " + qty + " / " + shift);
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {}
};
ref.addListenerForSingleValueEvent(valueEventListener);