How to higlight multiple items in a list in Android?
I have a ListActivity that presents a list of names from a database using a SimpleCursorAdapter. I want the user to be able to select 1 or more names by clicking them and then proceed to the next Activity. This should be a toggle, so that if the user clicks a selected name it will become de-selected. The underlying code is working fine, the problem is how to show the user which items are currently selected.
I looked at this solution: Android how to highlight a selection in a list and tried toggling .setSelected() on the TextView for the name. The problem is 开发者_C百科that the "selected" state apparently can only be true for one item in a list at a time. So if the user touches "Alice" then "Bob," only "Bob" will show as selected. Any thoughts on the best way to have a toggle-able highlight for multiple list items?
Have a look at the setChoiceMode method of the AbsListView class and its possible CHOICE_MODE_MULTIPLE parameter value.
精彩评论