I have a ListView
with several items so that these will be re-used during scrolling.
An item is composed by a couple of TextViews
and a RadioGroup
, containing 3 RadioButtons
.
The issue I'm having is that when I select for example a RadioButton
for each of the 5 items, when I scroll the list down and back up again, the selection I did in the beginning is not being saved (which means no RadioButton
or the wrong one will be shown as selected) while it can also happen that some RadioButtons
will appear as selected even if I never tapped on those.
I'm trying to save the checkedId
of the selection in a list but without luck.
Following my code:
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);
}
...
}
And the RadioGroupListener
radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
if (checkedId != -1) {
mappedSelectedAnswer.put(questionID, checkedId);
}
...
});
mappedSelectedAnswer
is a List with key questionID
, value the checkedId
As anyone have any suggestion to this issue?
Thanks