Android:如何使RadioGroup在ListView中正常工作?

发布于 2024-09-03 15:18:48 字数 288 浏览 2 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

就是爱搞怪 2024-09-10 15:18:48

当在适配器上调用 getView()(或 bindView(),如果您使用的是 CursorAdapter)时,您需要设置RadioGroup。 Android 会回收行,并且不会为您跟踪这些 RadioGroup 状态。

请参阅此处的示例项目,该项目具有 连续的RatingBar为通用技术。我的一本书中的这份免费摘录也涵盖了这一点。

When getView() (or bindView() if you are using a CursorAdapter) is called on your adapter, you need to set the state of the RadioGroup. Android recycles rows and is not going to track those RadioGroup 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文