android - Listview items are recreated in wrong order -
I found a list view with some string items in it. I am trying to save the state of listview in shared options in the onStop () method of the piece:
int i = 0; Hashset resultset = new hashset (resultdate.account ()); While (i & lt; resultAdapter.getCount ()) {resultsSet.add (resultAdapter.getItem (i)); I ++; } Editor.putStringSet ("RSLTS", resultset); Editor.commit ();
In this way, I recreate the list view status after relaunching the apple:
if (resultsSet! = Null) {for (string result : ResultsSet) {resultAdapter insert (result, 0); }}
As you can see, Im place each new row on the first place (0) of all list entries. The problem is that the list overview is created in something odd, for example:
List view before saving: 3 ... | 2 ... | 1 ...
List view after reloading: 2 ... | 1 ... | 3 ...
Find out why this is happening? Does anyone have any clue about this which is wrong?
Hashesets usually do not apply with a defined order, so it is not guaranteed that the order time Or when they will be written in stars.
Therefore, your options are:
1) Sort your string items on your case (like alphabet)
2) With your shared prefix given separator as a separate string (that you are certain that your data is not visible in) Then, when you read it back, to get the array of original strings, split the string obtained from the shared string from the shared separator.
Comments
Post a Comment