Search code examples
androidlistviewdialogsections

Section ListView in DIalog with "simple_list_item_multiple_choice"


So im using the commonsware example of sectioned listviews,here, but i use the multiselection option. The problem is when i get the getCheckedItemPositions(), if i have selected from the second section or above the positions dont really match. Seems that the Section Headers count as a position, so im having a problem of getting the checked items from the second,third...sections.....


Solution

  • ListView is the one keeping track of checked states, not the ListAdapter. Even the MergeAdapter does not really know what are headers and what are not -- they're all just contents to it.

    You could extend (or replace) MergeAdapter with something that knew concretely the difference between headers and detail rows. That adapter could give you a method to convert an absolute position (what ListView reports in getCheckedItemPositions()) into a section and position within that section.

    Also, for support on the CommonsWare books, open source code, and such, I recommend the cw-android Google Group.