title: Multi-level Listview with checkboxes - click listeners
body: <p>I want to be able to create a multi-level listview with checkboxes both at the parent and child level.</p>
  
  <p>I have been able to get a working listview using an ExpandableListAdapter, however I am having trouble creating a way for the checkboxes to communicate together.</p>
  
  <p>My wish is that when a parent checkbox is selected all of the sub check boxes will become selected and when it is deselected the opposite.  Additionally if the parent checkbox is not selected and a child gets selected then the parent checkbox should become selected.</p>
  
  <p>There are quite a few tutorials about a single layer of checkboxes but I have yet to find one describing  what I have stated above.</p>
  
  <p>Any help would be greatly appreciated!</p>
  
  <p>Here is my ExtendableListAdapter class :</p>
  
  <pre><code>public class ExpandableListAdapter extends BaseExpandableListAdapter {
  
  private Context _context;
  private List&lt;String&gt; _listDataHeader; // header titles
  private List&lt;Boolean&gt; _listDataBoolean; // header checkbox values
  // child data in format of header title, child title
  private HashMap&lt;String, List&lt;String&gt;&gt; _listDataChild;
  private List&lt;ArrayList&lt;Boolean&gt;&gt; _listChildBoolean;
  
  public ExpandableListAdapter(Context context, List&lt;String&gt; listDataHeader,
          HashMap&lt;String, List&lt;String&gt;&gt; listChildData,
          List&lt;Boolean&gt; listDataBoolean,
          List&lt;ArrayList&lt;Boolean&gt;&gt; listChildBoolean) {
      this._context = context;
      this._listDataHeader = listDataHeader;
      this._listDataChild = listChildData;
      this._listDataBoolean = listDataBoolean;
      this._listChildBoolean = listChildBoolean;
  }
  
  @Override
  public Object getChild(int groupPosition, int childPosititon) {
      return this._listDataChild.get(this._listDataHeader.get(groupPosition))
              .get(childPosititon);
  }
  
  @Override
  public long getChildId(int groupPosition, int childPosition) {
      return childPosition;
  }
  
  @Override
  public View getChildView(int groupPosition, final int childPosition,
          boolean isLastChild, View convertView, ViewGroup parent) {
  
      final String childText = (String) getChild(groupPosition, childPosition);
  
      if (convertView == null) {
          LayoutInflater infalInflater = (LayoutInflater) this._context
                  .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          convertView = infalInflater.inflate(R.layout.list_item, null);
      }
  
      TextView txtListChild = (TextView) convertView
              .findViewById(R.id.lblListItem);
  
      txtListChild.setText(childText);
  
      CheckBox chk = (CheckBox) convertView
              .findViewById(R.id.lblChildCheckbox);
      chk.setChecked(_listChildBoolean.get(groupPosition).get(childPosition));
  
      return convertView;
  }
  
  @Override
  public int getChildrenCount(int groupPosition) {
      return this._listDataChild.get(this._listDataHeader.get(groupPosition))
              .size();
  }
  
  @Override
  public Object getGroup(int groupPosition) {
      return this._listDataHeader.get(groupPosition);
  }
  
  @Override
  public int getGroupCount() {
      return this._listDataHeader.size();
  }
  
  @Override
  public long getGroupId(int groupPosition) {
      return groupPosition;
  }
  
  @Override
  public View getGroupView(int groupPosition, boolean isExpanded,
          View convertView, ViewGroup parent) {
  
      String headerTitle = (String) getGroup(groupPosition);
  
      Boolean bool = _listDataBoolean.get(groupPosition);
  
      if (convertView == null) {
          LayoutInflater infalInflater = (LayoutInflater) this._context
                  .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          convertView = infalInflater.inflate(R.layout.list_group, null);
      }
  
      TextView lblListHeader = (TextView) convertView
              .findViewById(R.id.lblListHeader);
      lblListHeader.setTypeface(null, Typeface.BOLD);
      lblListHeader.setText(headerTitle);
  
      CheckBox chk2 = (CheckBox) convertView
              .findViewById(R.id.lblHeaderCheckbox);
      chk2.setChecked(bool);
  
      return convertView;
  }
  
  @Override
  public boolean hasStableIds() {
      return false;
  }
  
  @Override
  public boolean isChildSelectable(int groupPosition, int childPosition) {
      return true;
  }
  </code></pre>
  
  <p>}</p>