What I’m doing is wanting to start off my ListView with 0 rows, download a list from the Internet, then populate the ListView with the downloaded contents. Seems easy enough, but arrays are proving to be an issue.
What’s happening is that I’m declaring my array in the only way ListView seems to want it
static String[] CONTENTS = new String[]{};
so that it populates with no rows. After downloading the contents through a thread, I then go to fill the array with what I’ve downloaded. The problem is that it doesn’t want to fill the array; if I initiate the array with one empty string, it will only let me fill it with exactly one row (so if I give it an array with more than one object, it doesn’t do anything). How can I expand on the array the ListView is taking data from, so I can fill it with more than the number of objects I’ve declared it with?
The closest I’ve been able to come was through the code
private String[] expand(String[] array, int size) {
String[] temp = new String[size];
System.arraycopy(array, 0, temp, 0, array.length);
for(int j = array.length; j < size; j++)
temp[j] = "";
return temp;
}
to expand the array and giving it the number of objects downloaded, but that still doesn’t seem to work.
Thanks in advance!
Don’t use arrays, use some implementation of List. (ArrayList will do the work). Collections are far superior than old-school arrays.
And when you add/remove elements to/from the
list, you must invoke