I'm developing some kind of "score tracker" app for a certain game. A user adds a certain amount of players (the number is currently unlimited) and those player names are then added to ArrayList. Then on the next activity, the user must choose a playername from a Spinner and enter a certain amount of "points" or let's say "score" for that player.
This is my current code for this:
public void submitScore(View v){
LinearLayout lLayout = (LinearLayout) findViewById (R.id.linearLayout);
final int position = playerList.getSelectedItemPosition();
EditText input = (EditText) findViewById(R.id.editText1);
final LinearLayout.LayoutParams lparams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
final TextView newTextView = new TextView(this);
String enteredText = input.getText().toString();
if (enteredText.matches(""))
{
emptyTextError();
}
else
{
//NEW TEXTVIEW
newTextView.setLayoutParams(lparams);
newTextView.setText(players.get(position) + " " + score);
newTextView.setTextSize(20);
lLayout.addView(newTextView);
}
}
As you can see, a user enters a certain score and a new textview is created containing player name and current score.
Now what I want to do is implement a feature that will track score for each player.
Example: The user added 2 players, one named John and one named Jack. The user then added 20 points to John and then after a while another 20, also to john. Now the textViews should look like this:
John 20
John 40
And then if the user will add 10 points to Jack and another 20 to John, TextViews should look like this:
John 20
John 40
Jack 10
John 60
This is what I don't know what to do. How do I implement a new int variable for each ArrayList element? Or is there a better way to do this than making int variables?
I need the app to automatically generate ints accoring to ArrayList, if the ArrayList contains 5 players, 5 ints need to be created because I don't know how many players the user will enter.