Android:如何使RadioGroup在ListView中正常工作?
我有一个 ListView,其中有一个 TextView 和一个 RadioGroup,每行有 4 个 RadioButtons 作为子项。 现在我可以在每一行中选择一个单选按钮。但是如果我滚动 ListView,我的选择就会消失或者无法正确显示。例如,我选择第一行中的RadioButton A,如果我滚动ListView然后再次返回到第一行,则RadioGroup中的RadioButtons都不会被选中,或者RadioButton C会被选中而不是A。 我该如何解决这个问题?我已经尝试了7天了,但仍然没有找到解决办法。有人可以帮助我吗?我将非常感激。
I have a ListView, which has a TextView and a RadioGroup with 4 RadioButtons as Children in each row.
Now i can select a RadioButton in each row. But if i scroll the ListView, my Selection is gone or it does not show correctly. For example, i choose the RadioButton A in the first row, if i scroll through the ListView and then go back to the first row again, either none of the RadioButtons in the RadioGroup is checked or RadioButton C is checked instead of A.
How can i fix this Problem? I have tried 7 days already, but still i find no solution. Can anybody help me? I'll be very appriciate of that.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当在适配器上调用
getView()
(或bindView()
,如果您使用的是CursorAdapter
)时,您需要设置RadioGroup
。 Android 会回收行,并且不会为您跟踪这些RadioGroup
状态。请参阅此处的示例项目,该项目具有
连续的RatingBar
为通用技术。我的一本书中的这份免费摘录也涵盖了这一点。When
getView()
(orbindView()
if you are using aCursorAdapter
) is called on your adapter, you need to set the state of theRadioGroup
. Android recycles rows and is not going to track thoseRadioGroup
states for you.See here for a sample project that has a
RatingBar
in a row for the general technique. This is also covered in this free excerpt from one my books.