I'm making an application(pedometer) in android-studio where I want to list data, that I take from the realtime-databse in firebase, into a Listview within my app. Due to linking dates with steps on each day I'm left with a setup that gives "Date:steps". What do I need to do in order to accumulate all steps from each day into a subtotal that only lists the total steps without the date?
This is for a leaderboard page I'm making where I want to organize all users from highest steps(walked on all dates, starts counting from date of registration) to the lowest. I've tried to make a for loop where I call for the user and steps walked, but the steps are still linked to the date.
I've tried looking at other similar questions, example: How do I efficiently iterate over each entry in a Java Map?
But I still can't make sense into it.
The code in question is:
myRef.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(@NonNull DataSnapshot dataSnapshot, String s) {
Map<String, Map> map = (Map<String, Map>) dataSnapshot.getValue();
int i = 0;
for (Map.Entry<String, Map> pair : map.entrySet()) {
Map steps = map.get("steps");
arrayList.add(" " + map.get("username") + " " + steps);
arrayAdapter = new ArrayAdapter<>(Leaderboard.this , android.R.layout.simple_list_item_1 , arrayList);
}
listView.setAdapter(arrayAdapter);
}
I want to get the output:
Name 200
with number "200" being the total amount of steps walked over all dates.
The output I am getting at the moment is:
Name {Date=37,Date=40,Date=12,Date=67,Date=44}
Name {Date=37,Date=40,Date=12,Date=67,Date=44}
Name {Date=37,Date=40,Date=12,Date=67,Date=44}
What would I need to do in order to remove the dates, and list only the values(steps) as a subtotal of all steps walked over said listed dates(per user)?