I have a listview with three Radio Buttons in a list item, Issue is that when I scroll list view, the radio buttons selected position gets changed. So please let me know how to keep radio button's selection intact even if I scroll list view. My code is,
RadioGroupAdapter.java
public RadioGroupAdapter(Context context, int layoutResourceId,
Option[] data) {
super(context, layoutResourceId, data);
this.layoutResourceId = layoutResourceId;
this.context = context;
this.data = data;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
MatrixHolder holder = null;
if (row == null) {
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
holder = new MatrixHolder();
holder.txtTitle = (TextView) row.findViewById(R.id.heading);
holder.group = (RadioGroup) row.findViewById(R.id.radio_group1);
final RadioButton[] rb = new RadioButton[2];
for(int i=0; i<2; i++){
rb[i] = new RadioButton(context);
// rb[i].setButtonDrawable(R.drawable.single_radio_chice);
rb[i].setId(i);
RadioGroup.LayoutParams params = new RadioGroup.LayoutParams(
0, LayoutParams.WRAP_CONTENT);
params.weight=1.0f;
params.setMargins(5, 0, 5, 10);
holder.group.addView(rb[i],params); //the RadioButtons are added to the radioGroup instead of the layout
}
// ((MatrixHolder)holder).group.clearCheck();
row.setTag(holder);
} else {
holder = (MatrixHolder) row.getTag();
}
Option option = data[position];
holder.txtTitle.setText(option.title);
return row;
}