I'm facing a problem that I don't arrive to resolve:
I read an ArrayList from the phone:
ArrayList<Game> gameResult = writeRead.getArrayList(this);
I put the object gamer from each game in a new ArrayList:
ArrayList<Gamer> gamerList = new ArrayList<>();
for (int i = 0; i < gameResult.size(); i++) {
gamerList.add(gameResult.get(i).getWinnerGamer());
}
now, what I would like is to:
- add
Gamerin anArrayListif not already present - if present, add ++ to a parameter named
LeaderPoints - sort by point
It's about a leaderboard activity with a custom ArrayList, but I don't arrive to do it.
All my code:
private void setGamerList() {
ArrayList<Game> gameResult = writeRead.getArrayList(this);
ArrayList<Gamer> gamerList = new ArrayList<>();
ArrayList<Gamer> gamerNoDuplicate = new ArrayList<>();
if (gameResult != null) {
for (int i = 0; i < gameResult.size(); i++) {
gamerList.add(gameResult.get(i).getWinnerGamer());
}
}
Log.i(TAG, "--------------------------------");
Collections.sort(mGamerList, (o1, o2) ->
o2.getLeaderboardScore().compareTo(o1.getLeaderboardScore()));
}
Gamerclass