title: ExpandableListView with RadioButtons.  Select Value For One RadioGroup, Several More Get Selected When Group Expands
body: <p>I am replicating an inspection form for a piece of equipment in an android app.  There is an ExpandableListView where group data consists of the different systems of the machine and child data contains the checklist of items with a RadioGroup for the technician to indicate the pass/fail status of the item. All works great except when selecting a value for a RadioButton in one child, it selects a value for the same RadioButton in other groups. So if I had:</p>
  
  <pre><code>Group 1
    Question 1
      Passed
      Failed
      Corrected
      NA
    Question 2
      Passed
      Failed
      Corrected
      NA
  Group 2
    Question 1
      Passed
      Failed
      Corrected
      NA
    Question 2
      Passed
      Failed
      Corrected
      NA
  </code></pre>
  
  <p>If I select Passed in both questions in Group 1, without ever having gone into group 2, when expanded, 1 or both of the RadioGroups there will have Passed selected also. </p>
  
  <p>The layout I am using to create the child group with the RadioGroup looks like</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:layout_marginLeft="15dip"&gt;
  &lt;TextView
  android:id="@+id/questionText"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"/&gt;
  &lt;RadioGroup
  android:tag="actionGroup"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:orientation="vertical"&gt;
  &lt;RadioButton
    android:tag="passed"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Passed"/&gt;
  &lt;RadioButton
    android:tag="failed"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Failed"/&gt;
  &lt;RadioButton
    android:tag="corrected"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Corrected"/&gt;
  &lt;RadioButton
    android:tag="na"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="NA"/&gt;
  &lt;/RadioGroup&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>Instantiation of BaseExpandableListAdapter</p>
  
  <pre><code>ExpandableListView inspectionQuestions = (ExpandableListView) FindViewById(Android.Resource.Id.List);
  inspectionQuestions.SetAdapter(new ExpAdapter(this));
  </code></pre>
  
  <p>BaseExpandableListAdapter</p>
  
  <pre><code>public class ExpAdapter : BaseExpandableListAdapter
  {
      private readonly Context context;
      Questions questions = new Questions();
      private int seed = 1000;
  
      public ExpAdapter(Context ctx)
      {
          context = ctx;
      }
  
      public override Object GetChild(int groupPosition, int childPosition)
      {
          return null;
      }
  
      public override long GetChildId(int groupPosition, int childPosition)
      {
          return 0;
      }
  
      public override View GetChildView(int groupPosition, int childPosition, bool isLastChild, View convertView, ViewGroup parent)
      {
          if (convertView == null)
          {
              LayoutInflater inflater = (LayoutInflater) context.GetSystemService(Context.LayoutInflaterService);
              convertView = inflater.Inflate(Resource.Layout.inspection_row_2, null);
          }
  
          int currentID;
  
          TextView question = (TextView) convertView.FindViewById(Resource.Id.questionText);
          RadioGroup radio = (RadioGroup) convertView.FindViewWithTag("actionGroup");
          radio.Id = seed++;
          RadioButton pass = (RadioButton) convertView.FindViewWithTag("passed");
          pass.Id = seed++;
          RadioButton fail = (RadioButton) convertView.FindViewWithTag("failed");
          fail.Id = seed++;
          RadioButton correct = (RadioButton)convertView.FindViewWithTag("corrected");
          correct.Id = seed++;
          RadioButton na = (RadioButton)convertView.FindViewWithTag("na");
          na.Id = seed++;
  
          string[][] items = questions.childItems();
          question.Text = items[groupPosition][childPosition];
  
          return convertView;
      }
  
      public override int GetChildrenCount(int groupPosition)
      {
          return questions.childItems()[groupPosition].Length;
      }
  
      public override Object GetGroup(int groupPosition)
      {
          return null;
      }
  
      public override long GetGroupId(int groupPosition)
      {
          return 0;
      }
  
      public override View GetGroupView(int groupPosition, bool isExpanded, View convertView, ViewGroup parent)
      {
          if (convertView == null)
          {
              LayoutInflater inflater = (LayoutInflater) context.GetSystemService(Context.LayoutInflaterService);
              convertView = inflater.Inflate(Android.Resource.Layout.SimpleExpandableListItem1, null);
          }
  
          TextView groupName = (TextView) convertView.FindViewById(Android.Resource.Id.Text1);
  
          QuestionGrouper grouper = new QuestionGrouper();
          groupName.Text = grouper.groupItems()[groupPosition];
  
          return convertView;
      }
  
      public override bool IsChildSelectable(int groupPosition, int childPosition)
      {
          return true;
      }
  
      public override int GroupCount
      {
          get { return 9; }
      }
  
      public override bool HasStableIds
      {
          get { return false; }
      }
  }
  </code></pre>
  
  <p>EDITED GetChildView per Suggestion:</p>
  
  <pre><code>   public override View GetChildView(int groupPosition, int childPosition, bool isLastChild, View convertView, ViewGroup parent)
      {
          if (convertView == null)
          {
              LayoutInflater inflater = (LayoutInflater) context.GetSystemService(Context.LayoutInflaterService);
              convertView = inflater.Inflate(Resource.Layout.inspection_row_2, null);
          }
  
          TextView question = (TextView) convertView.FindViewById(Resource.Id.questionText);
  
          RadioGroup radio = (RadioGroup) convertView.FindViewById(Resource.Id.activityGroup);
          int count = radio.ChildCount;
  
          if (count == 4)
          {
              return convertView;
          }
  
          RadioButton pass = new RadioButton(context) {Text = "Passed"};
          RadioButton fail = new RadioButton(context) {Text = "Failed"};
          RadioButton correct = new RadioButton(context) {Text = "Corrected"};
          RadioButton na = new RadioButton(context) {Text = "NA"};
  
          radio.AddView(pass);
          radio.AddView(fail);
          radio.AddView(correct);
          radio.AddView(na); 
  
          string[][] items = questions.childItems();
          question.Text = items[groupPosition][childPosition];
  
          return convertView;
      }
  </code></pre>