Wrong item checked when filtering ListView in android

Posted by aspartame on Stack Overflow See other posts from Stack Overflow or by aspartame
Published on 2010-03-21T16:40:41Z Indexed on 2010/03/21 17:11 UTC
Read the original article Hit count: 498

Filed under:
|
|
|

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

© Stack Overflow or respective owner

Related posts about android

Related posts about listview