I have an application with a quizz and an activity where I want there to be the top 5 score with the players who made those scores. I have 2 ArrayLists, that stores the scores for one and the other stores the names of the players. I managed to make the list with the scores but i don't know how to have the right names next to the peer scores.
An image of what I have : https://i.stack.imgur.com/7PxmR.png
And an image of what I am looking for : https://i.stack.imgur.com/HNEsU.png
I have tried with a Map but i didn't know that 2 same keys can not be stored so that's impossible, but there may be a way to have some kind of arraylist with indexes but that can have 2 different informations, I don't know.
My 2 ArrayLists :
public static ArrayList<Integer> scoresList = new ArrayList<>();
public static ArrayList<String> namesList = new ArrayList<>();
My way to to have the 5 bests scores :
public class HistoryActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_history);
TextView first = (TextView) findViewById(R.id.history_activity_first);
TextView second = (TextView) findViewById(R.id.history_activity_second);
TextView third = (TextView) findViewById(R.id.history_activity_third);
TextView fourth = (TextView) findViewById(R.id.history_activity_fourth);
TextView fifth = (TextView) findViewById(R.id.history_activity_fifth);
Collections.sort(scoresList, Collections.reverseOrder());
first.setText("Best score is : " + scoresList.get(0));
if (scoresList.size() >= 2) {
second.setText("2nd best score is : " + scoresList.get(1));
}
if (scoresList.size() >= 3) {
third.setText("3rd best score is : " + scoresList.get(2));
}
if (scoresList.size() >= 4) {
fourth.setText("4th best score is : " + scoresList.get(3));
}
if (scoresList.size() >= 5) {
fifth.setText("5th best score is : " + scoresList.get(4));
}
}
}
Thanks