I have a bunch of nested data stored in FirebaseRealTimeDatabase like this:
I am able to retrieve the dataset, that is the profile and their respective scores.
ArrayList<String> profileNameList = new ArrayList();
ArrayList<String> profileStatusList = new ArrayList();
ArrayList<int> scoreList = new ArrayList();
databaseReference.child("players")
.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Iterable<DataSnapshot> children = dataSnapshot.getChildren();
for (DataSnapshot child : children) {
Profile profile = child.child("profile").getValue(Profile.class);
Scores scores= child.child("scores").getValue(Scores.class);
profileNameList.add(profile.getName());
profileStatusList.add(profile.getStatus());
scoreList.add(scores.getScore());
}
}
I am then using using Collections.sort(scoreList)
to sort the scores from lowest to highest. My challenge however is, how can I associate the sorted scores(from the lowest to the highest) again with the player profile, e.g.
Gavin - 15
Rico - 40
Any help is appreciated.