title: ExpandableListView child's radio button
body: <p>I have an Expandable listview where each item (group) has multiple children, and each child has a radio button. In each group, only one radio button can be selected.</p>
  
  <p>In my attempts, I am able to make only one radio button active, however not in each group, but in the whole list. Also when a group is expanded the the position of the radio button selected is changed.</p>
  
  <p>Here my code for the <code>setOnChildClickListener</code></p>
  
  <pre><code>ExpListView.setOnChildClickListener(new OnChildClickListener() {
  
      public boolean onChildClick(ExpandableListView expandableListView, View view, int groupPosition, int childPosition, long id) {
  
          Log.v("TESTING","On Child Click");
          if (groupPosition == 0) {
              Log.v("TESTING","OnChildClick - groupPosition = 0");
              RadioButton last = checkedRadio1;
              RadioButton r = (RadioButton) view.findViewById(R.id.radio_button);
  
              if (last != null)
                  last.setChecked(false);
              r.setChecked(true);
              checkedRadio1 = r;
  
              return true;
          }
          else if (groupPosition == 1) {
              RadioButton last = checkedRadio2;
              RadioButton r = (RadioButton) view.findViewById(R.id.radio_button);
  
              if (last != null)
                  last.setChecked(false);
              r.setChecked(true);
              checkedRadio2 = r;
  
              return true;
          }
          else if(groupPosition == 2) {
              RadioButton last = checkedRadio3;
              RadioButton r = (RadioButton) view.findViewById(R.id.radio_button);
  
              if (last != null)
                  last.setChecked(false);
              r.setChecked(true);
              checkedRadio3 = r;
  
              return true;
          }
  
          else return false;
      }
  });
  </code></pre>
  
  <p>And here's the code for the <code>setOnItemLongClickListener</code> (I want it on the long click)</p>
  
  <pre><code>ExpListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
  
      public boolean onItemLongClick(AdapterView&lt;?&gt; adapterView, View view, int i, long l) {
         if (ExpandableListView.getPackedPositionType(l) == ExpandableListView.PACKED_POSITION_TYPE_GROUP) {
            int groupPosition = ExpandableListView.getPackedPositionGroup(l);
  
              if (lastExpandedPosition != -1
                      &amp;&amp; groupPosition != lastExpandedPosition) {
                  ExpListView.collapseGroup(lastExpandedPosition);
              }
              ExpListView.expandGroup(groupPosition);
              lastExpandedPosition = groupPosition;
  
              return true;
          }
  
          else return false;
      }
  });
  </code></pre>
  
  <p>How can make sure that the position of the child is the right one? For instance if I check second child in the first group, then expand the second group (the first group automatically collapses) I have the first child in the second group checked. How can I solve this? And how can I make the 'single select' mode only between children of the same group?</p>
  
  <p>Thank you for your help!</p>