Skip to content Skip to sidebar Skip to footer

How Can I Save The State Of The Checkboxes In A Custom Listview Using Sharedpreferences?

I have checkboxes in my custom listview, I'm using a boolean array to save the state of these checkboxes. I want to make the state of checkboxes persistent through out the lifetime

Solution 1:

I know that this can be achieved through sharedpreferences, but I don't exactly know how this can be done.

There is no option to push serializable objects into sharedpreferences. Because of that, you'll be forced to convert the boolean array to one of the supported types. The only one I can see making sense would be to convert the state of the array into a string like :

"0|1|0|1|1"

Then push that into the shared preferences. To do this you could use the Arrays.toString(boolean []). You will, however, have to write a parse method for extracting the value back out from the SharedPreferences. That is probably the easiest option to accomplish this.

Post a Comment for "How Can I Save The State Of The Checkboxes In A Custom Listview Using Sharedpreferences?"