I have managed to reload the list item in a list when the activity call’s it’s onStop() method. Here I want to store what’s generated by pressing a button. If you have read my previous few posts you will know what’s happening but this is a different question.
Using my code:
listLimit = listItems.size() - 1;
for( int i = 0; i < listLimit; i++ )
{
storeList[i] = listItems.get( i ).toString();
tempDataStore = storeList[i];
editor.putString( DATA,tempDataStore );
}
editor.commit();
I store the values of the storeList. I know that the way it’s done above will basically overwrite the tempDataStore every time it iterates through. Which means when it’s recalled in the onCreate() method only the last value of the list will be loaded. So how do I fix this? How can I uniquely identify each list item without creating a new String variable for each?
UPDATE
I kinda of sorted it by changing the key on and keeping the value. When I add them like this:
listItems.add( 0, settings.getString( DATA+"0",tempDataStore ) );
It works. But when I try to do the same thing in a for loop, like so:
for( int i = 0; i < listLimit; i++ )
{
listItems.add( i, settings.getString( DATA+""+i,tempDataStore ) );
}
Noting happens. Why so?
I determined the reason – it was because listLimit was actually equal to zero therefore the loop would never start. So to rectify this I stored the value of the list like so:
And then recalled it to the start of the for loop here:
Hope this helps whoever