I am retrieving many values under id, but it's not working. It should be very easy, but i am stuck.
This is my data structure:
Attendance
x73aXTQHXHXHQ
current
value: "Bill Gates"
company
value: "Apple"
history
-La7wew7hdxccdcdzssf
value: 156000000001
-La7wptthd3ceeqoz34f
value: 156000000002
-La7wew7hdxccdcdzssf
value: 156000000003
I've tried this code and succeed only retrieved children count Output: 3
, but not children values 156000000001
like I want. This is my code, any help thank you.
if (uid != null) {
ref.child(uidKeys).child(uid).child("history").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
int countUnderHistory = (int) dataSnapshot.getChildrenCount();
long[] dataHistory = new long[countUnderHistory];
int index = 0;
for (DataSnapshot push : dataSnapshot.getChildren()) {
NonDuplicateAttendance nDa = push.getValue(NonDuplicateAttendance.class);
if (nDa != null) {
dataHistory[index] = nDa.getuHistory();
}
index++;
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
NonDuplicateAttendance class:
package com.example.aspireone.myapplication;
public class NonDuplicateAttendance {
private long value;
public NonDuplicateAttendance(long value) {
this.value = value;
}
public long getuHistory() {
return value;
}
}
Since you didn't share your
NonDuplicateAttendance
I can't say what's going wrong there. But to print the values in the history:Edit
Your class doesn't work, because it doesn't declare a public
value
property. To fix this:The changes:
value
field is public, so that the SDK recognizes it as matching thevalue
property in your JSON.getuHistory()
method to be excluded from the database, since otherwise the SDK will write auHistory
property too.