Android:如何使 RadioGroup 在 ListView 中正常工作? [英] Android: How to make RadioGroup work correctly in a ListView?

查看:28
本文介绍了Android:如何使 RadioGroup 在 ListView 中正常工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 ListView,它有一个 TextView 和一个 RadioGroup,每行有 4 个 RadioButtons 作为子项.现在我可以在每一行中选择一个 RadioButton.但是如果我滚动 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.

推荐答案

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

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.

查看此处获取示例项目RatingBar 用于一般技术.这也在我的一本书中的这个免费摘录中有所介绍.

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.

这篇关于Android:如何使 RadioGroup 在 ListView 中正常工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆