ListView item won't stay “selected”

后端 未结 10 1330
暗喜
暗喜 2020-12-10 05:50

I want to change the background of a listview item when the user clicks it. Kind of like the Honeycomb settings page (Although I\'m not dealing with just settings so I\'m no

10条回答
  •  清歌不尽
    2020-12-10 06:35

    By default, 'Selected' isn't the same as 'Clicked' when you're using a touch interface - something that cause me some real headaches when I started Android development.

    To support both users that navigate by touch and users that use scrollwheels/trackballs, you might want to use setSelection, and do your manipulation in an AdapterView.OnItemSelectedListener implementation (set with setOnItemSelectedListener).

    Another gotcha is that setSelection won't highlight an item if the last event was a touch event.

    I'd recommend that you create a custom View for your list items, and handle highlighting in there.

    Hope this helps,

    Phil Lello

提交回复
热议问题