views:

274

answers:

1

I have a ListView with multiple choice entries where some are checked from the beginning using

setItemChecked(position, true);

I combine this with the filtering option

setTextFilterEnabled(true)

so it's easy to find a specific entry in the list.

The problem is that when I filter the list the entries switch position in the list view. Take for example three entries: 'A', 'B' and 'C' where 'C' is checked beforehand (i.e. the entry at position 3 in the list). When I type a 'C' on the keyboard, only the 'C' entry is displayed (as intended). Now 'C' is not checked anymore, since the entry has moved from the checked position 3 to the unchecked position 1 in the list.

This behavior leads to some not very welcome effects in the app. Is there a way to "move the selection with the filtering", i.e. bind the checked state to the entry and not to its initial position in the list? Or do I need to find a new approach?

Thanks,

Linus

+1  A: 

Maintain a list of the selected items, and whenever the list is repopulated check if that id (not position) exists in the list, and set as selected.

Pentium10