0

I want to use the shared preferences to save a list of integers. it's simple by using the putStringSet() methode.

final Set<String> set = new TreeSet<String>();

for (final Station station : stations) {
    set.add(String.valueOf(station.getId()));
}
editor.putStringSet(USER_STATIONS, set);

but there's a big problem. the list isn't sorted anymore after loading the prefereneces with getStringSet()

Is there an other/better way than save the list as json or as a string with comma seperated values?

passsy
  • 5,162
  • 4
  • 39
  • 65
  • I like the idea of a comma separated string if it's just integers. You could also fake an array by doing something like [this](http://stackoverflow.com/a/11050845/752320). – Geobits Jan 20 '13 at 15:38

1 Answers1

0

I think there is no way to save sorting with preferences (at least SharedPreferences reference is clear about that) , instead you can do it with LiteSQL or by creating a custom file: http://developer.android.com/guide/topics/data/data-storage.html#filesInternal .

XorOrNor
  • 8,868
  • 12
  • 48
  • 81