I am reading from a comma seperated file and splitting the contents into an array. I am doing this in a while loop so I would want my arrays to have have a different name dynamically because the last line in the file end up overwriting my array content. Below is a fragment of my the code involved.
TextView txt1;
TextView txt2;
Scanner in = new Scanner(result);
in.nextLine(); //skip first line
while(in.hasNextLine()){
String line = in.nextLine();
String []dataset = line.split(",");//store values in array
txt1.setText(dataset[4]);//Should be 5th element of first line
txt2.setText(dataset[4]);//Should be 5th element of second line
}
As you can see from the above code I want to set the value of txt1 to a val in the first line of my file and similarly to the txt2. I read HashMaps or Maps or ArrayList would help me but I am not sure how to achieve this.
If I understand what you want to do correctly it is you want txt1 to equal the 5th element in the array on the 1st line and txt2 to have the text of the 5th element on the 2ed line (your comment says 3ed element but the code is pulling the 5th).
This can be achieved with conditionals and a counter.
EDIT:
So now that I know you want an array of arrays the set up is easy. The outer array should be mutable if you dont know the amount of data you are processing before hand.
if you wanted to you could also create these text labels and store handels to them in a similar manner and set the text as you go.