I have a people model that has a name, age, and sex. Now, I want to filter by age and get only the name of the oldest person. However, I can't find a way to do that. This is how my data looks like.
So far I have been able to get all the person's information like this:
Query oldest = FirebaseDatabase.getInstance().getReference("people").orderByChild("age").limitToLast(1);
oldest.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot datas: dataSnapshot.getChildren()){
People peolpe = datas.getValue(People.class);
}
displayName(people.name);
}
@Override
public void onCancelled(DatabaseError databaseError) {
Toast.makeText(MainActivity.this, ""+databaseError, Toast.LENGTH_SHORT).show();
}
});