I am using ExpandableListView, and the child row each has a textview, and checkbox within it.
What I want to do is, when a user pushes a button, the activity figures out which items are ‘checked’ and do something with those items.
I read many posts on how ExpandableListView and checkboxes currently don’t work well, and how I need to keep an additional data structure to keep track of what’s has been selected, and not. This post covers that issue:
ExpandableListView and checkboxes
Done! I now can keep track of what’s been selected, and what’s not been selected.
Now I want to tackle the problem of check boxes not showing their states. I have noticed that the check boxes change randomly when:
- screen rotation changes
- a group collapses/opens
I know that it’s possible to detect these events.
I want to know if there’s a way to set the check boxes by hand. I initially tried
ExpandableListView elv = getExpandableListView();
for(int i = 0; i < elv.getChildCount(); i++) {
CheckBox checkbox = ... somehow get checbox within the list
checkbox.setChecked(checkList.at(i, j));
}
where i, and j indicate which group, and children, and checkList keeps track of checked/unchecked items.
However, I noticed that value of getChildCount() depends on how many groups are open, and does not necessarily tell me which list item I can manipulate.
ExpandableListView has been used, and someone must have had a way of getting around this issue. Is there a smart solution to this? Specifically, I am looking for ways to check/uncheck appropriate items in the list at onGroupExpand and onConfigurationChange (or similar events.)
Thank you in advance!
Check following sample Expandable list adapter