I have radio buttons in listview, for every column a radio button and a checkbox will added at the end. But user should be able select only one radio button in the list shown, i tried looking in net where all i can get how to list radio buttons using adapter which has been done already by me. Advance thanks. Below is my code:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View view;
ViewHolder holder;
int selected;
ListCollection person = items.get(position);
if(convertView == null) {
view = mInflater.inflate(R.layout.contact_adapter, parent, false);
holder = new ViewHolder();
holder.name = (TextView)view.findViewById(R.id.user_name);
//holder.primary = (RadioButton) view.findViewById(R.id.primary_radio);
holder.inVoice = (CheckBox) view.findViewById(R.id.checkBox1);
holder.radioGroup = (RadioGroup) view.findViewById(R.id.radio_group);
view.setTag(holder);
} else {
view = convertView;
holder = (ViewHolder)view.getTag();
}
holder.name.setText(person.text);
selected = holder.radioGroup.getCheckedRadioButtonId();
holder.radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
// TODO Auto-generated method stub
int childCount = group.getChildCount();
for (int x = 0; x < childCount; x++) {
RadioButton btn = (RadioButton) group.getChildAt(x);
if (btn.getId() == checkedId) {
}
}
}
});
RadioButton button = new RadioButton(context);
button.setText("Primary");
button.setid(i);
holder.radioGroup.addView(button);
return view;
}