I am trying to save some values in a arraylist but somehow they all get overwritten ending up with only 1 value in the arraylist (200).
final String[] titles = new String[urls.length];
for (int i = 0; i < titles.length; i++){
ArrayList<Integer> valuesList = new ArrayList<Integer>();
valuesList.add(page.getTopicCount()); // returns 4 values (50,100,150,200)
System.out.println("Element: " + valuesList.toString());
// returns only value 200
}
The code page.getTopicCount()
returns the 4 values in 1 line (50 100 150 200) only the last one (200) gets added to the arraylist but i am trying to find a way to save them all 4 seperately.
What options do i have? (SharedPreferences, saving to file, do i have to build another loop)?
I already did some research and ended up on this page but i don`t know if this will work.
Ps: the 4 values are constantly changing, thus it is no option to add them as:
valuesList.add("50");
valuesList.add("100");
etc..
Edit: getTopicCount is part of a Saxparser class, see below code snippet:
public void endElement(final String uri, final String localName, final String qName)
throws SAXException {
//
} else if (localName.equals("topiccount")) {
in_topiccount = true;
sb = new StringBuilder();
}
//
else if (localName.equals("topiccount")) {
in_topiccount = false;
forumPage.setTopicCount(Integer.parseInt(sb.toString())); //returns 50 100 150 200
sb = null;
}
//
}