I am trying to add a monthly scoreboard but it seems to be a little bit difficult to me. I don't know how to just take a specific value to some list or array. Like Date, only date with 09.01.2017 values. If I could do that then I think that I can sort them by value.
FirebaseDatabase database = FirebaseDatabase.getInstance();
final DatabaseReference highscoreRef = database.getReference();
// Ordering with score and adding key values as string to nameList and scoreList
highscoreRef.orderByChild("score").limitToLast(10).addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot snapshot, String previousChildKey) {
try {
nameList.push(snapshot.child("name").getValue().toString());
scoreList.push(snapshot.child("score").getValue().toString());
} catch (Exception e) {
//Toast.makeText(getApplicationContext(), "Error fetching data.", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onCancelled(DatabaseError databaseError) {
Toast.makeText(getApplicationContext(), "Error sending data.", Toast.LENGTH_LONG).show();
}
});
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…