Search code examples
androidcheckboxexpandablelistviewsavestate

How to save state of checkboxes in expandable listview - Android


I'm displaying entries from SQLite database in Expandable ListView and everything is working correctly but, I wanted to add in a checkbox right next to all children. Every time I check a checkbox and then scroll down or contract the checkbox which I had checked it doesn't save the state of the checkbox. I know that the list is recycled whenever I scroll down and expand the groups and so forth. How can I save the state of every checkbox (by every child)? I have a class which extends CursorTreeAdapter and there is no "childPosition" in the methods. What do I need to do in order to save the state?


Solution

  • you can have an array of boolean flags with same size as sum of list elements and set and get the checked value from this array for any component.