I am using expandable list view in my app and in its child view,i am using a custom list of radio buttons.The problem here is that i want to make sure that only one radiobutton should be selected at a time.If one radio button is selected,other should be deselected.This is the code i am using:
@Override
public View getChildView(int groupPosition,int childPosition,
boolean isLastChild, View convertView, ViewGroup parent)
{
m_position = childPosition;
View l_view = convertView;
if (l_view == null)
{
LayoutInflater l_vi = (LayoutInflater)m_context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
l_view = l_vi.inflate(R.layout.singleradiobutton, null);
ViewHolder viewHolder = new ViewHolder();
viewHolder.l_nameRadioButton = (RadioButton) l_view.findViewById(R.id.radioButton);
l_view.setTag(viewHolder);
}
EnteringValuesToArrayList l_enteringValuesInstance = m_itemsOfAdapterArrayList.get(childPosition);
String l_nameOfContact = l_enteringValuesInstance.GetNameOfEntry();
if (l_nameOfContact != null)
{
ViewHolder holder = (ViewHolder) l_view.getTag();
if (holder.l_nameRadioButton != null)
{
holder.l_nameRadioButton.setText(l_nameOfContact);
}
if(m_timerValue != 0 && l_enteringValuesInstance.GetTimerValueOfEntry() == m_timerValue)
holder.l_nameRadioButton.setChecked(true);
else
holder.l_nameRadioButton.setChecked(false);
holder.l_nameRadioButton.setOnClickListener(new OnItemClickListener(childPosition,holder.l_nameRadioButton.getText(),holder.l_nameRadioButton));
}
return l_view;
}
private class OnItemClickListener implements OnClickListener
{
private int l_positionOfItemClicked;
private CharSequence l_text;
private RadioButton l_radioButton;
OnItemClickListener(int position, CharSequence text,RadioButton l_nameRadioButton)
{
this.l_positionOfItemClicked = position;
this.l_text = text;
this.l_radioButton = l_nameRadioButton;
}
@Override
public void onClick(View arg0)
{
l_radioButton.setChecked(true);
}
}
I searched a lot,but did not get the solution of the problem.Please help me.Thanks in advance.
Similar question is asked in this How to use RadioGroup in ListView custom adapter?
You can create a custom view in your case.
Hope this helps.