Mark Olsen
Mark Olsen

Reputation: 105

Android save state of listview with multipleChoice

I have a listview that contains some values with the multipleChoice enabled in my xml file. I want to be able to save what has been checked by the user when the app is exited, then re-check what they have selected upon opening again. My code works for a radio group, but I can't seem to get it to work for this.

EDIT: Got this working by using some for loop trickery at the end.

Upvotes: 4

Views: 725

Answers (2)

rekaszeru
rekaszeru

Reputation: 19220

as @BGS wrote, SharedPreference would solve your problem. Check out this post: MultiChoice Preference Widget for Android.

Here the values of the checkboxes are stored in a [special-separator]-separated string, and passed to the caller as a String array containing the selected values.

I'm using this approach, and it works great so far.

Upvotes: 1

bgs
bgs

Reputation: 1250

You could use SharedPreferences to persist your selections.

Upvotes: 1

Related Questions