Android ListView with RadioButton in singleChoice mode and a custom row layout

前端 未结 7 1922
野趣味
野趣味 2020-12-06 04:13

I have a ListView, which is in singleChoice mode. All I want is to display a RadioButton to the side, that when clicked highlights to say i

7条回答
  •  -上瘾入骨i
    2020-12-06 04:52

    Do bear in mind that in the ListView row items are RECYCLED. This is likely to explain why actions on one row are affecting another. Dig around in Mark's book and you'll find coverage of this.

    If you're using an adapter with the list, you can use getView() on an adapter to add a click handler to each row as it's created/recycled, and make sure the state is managed correctly as the row items are created and recycled.

    My approach is to store the state in my own data structure, and then use getView() to mirror that in the UI as the user scrolls up and down the ListView. There may be a better solution, but that works for me.

提交回复
热议问题