问题描述
我有一个ListView,它有一个TextView和4单选按钮为儿童每一行中的RadioGroup中。现在,我可以选择每个行中的单选按钮。但是,如果我滚动的ListView,我的选择是走还是不正确显示。例如,我选择了一个单选按钮排在第一位,如果我滚动ListView控件,然后再回到第一排一遍,要么没有在RadioGroup中的单选按钮的检查或单选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.
推荐答案
在 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的:如何使一个ListView RadioGroup中正常工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!