我在我的应用程序及其子视图中使用可扩展列表视图,我正在使用单选按钮的自定义列表。这里的问题是我想确保一次只能选择一个单选按钮。如果一个单选按钮已选中,其他应取消选中。这是我正在使用的代码:
@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);
}
}
我搜索了很多,但没有得到问题的解决方案。请帮助我。在此先感谢。