我有一個ListView
幾個項目,以便這些將在滾動期間被重新使用。 一個項目由幾個TextViews
和一個RadioGroup
組成,其中包含3個RadioButtons
。在列表中記住RadioButton的選定狀態
我遇到的問題是,當我爲5個項目中的每一個選擇例如RadioButton
,當我向下滾動列表並重新備份時,我在開始時所做的選擇未被保存(其中意味着沒有RadioButton
,或者錯誤的將顯示爲選中狀態),但即使我從未點擊過,也會出現某些RadioButtons
將顯示爲選中狀態。
我試圖將選擇的checkedId
保存在列表中,但沒有運氣。
下面我的代碼:
public View getView(int position, View convertView, ViewGroup parent) {
...
int questionID = question.getQuestionID();
if (mappedSelectedAnswer.containsKey(questionID)) {
radioGroup.check(mappedSelectedAnswer.get(questionID));
} else {
radioGroup.check(-1);
}
...
}
而且RadioGroupListener
radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
if (checkedId != -1) {
mappedSelectedAnswer.put(questionID, checkedId);
}
...
});
mappedSelectedAnswer
是關鍵questionID
,值列表中的checkedId
由於任何人有任何建議,這個問題?
感謝
這可能是由於當您滾動時您的RadioGroup被回收。 [看看這個答案。](http://stackoverflow.com/questions/2937581/android-how-to-make-radiogroup-work-correctly-in-a-listview) –
正如我已經指定,我已經知道什麼是因爲,我需要的是一個有效的解決方案。我檢查了你鏈接的答案,但我沒有明白。你可以說得更詳細點嗎?謝謝 – carlodonz