My current code is this:
String key = FirebaseDatabase.getInstance().getReference().child("posts").child("???").child("numLikes").toString;
How to get numLikes value?
My current code is this:
String key = FirebaseDatabase.getInstance().getReference().child("posts").child("???").child("numLikes").toString;
How to get numLikes value?
final ArrayList<Integer> arrayList = new ArrayList<>();
DatabaseReference dbRef = FirebaseDatabase.getInstance().getReference("posts");
dbRef.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
arrayList.clear();
for (DataSnapshot ds: dataSnapshot.getChildren()) {
int numLike = ds.child("numLikes").getValue(Integer.class);
arrayList.add(numLike);
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
Try this code, here you don't know pushkey so I have used forEach loop to jump one level down. The arraylist used here will contain all numLikes for your users.