title: Loading data to header and child list
body: <p>I want to load data into expandable list view, mProductList contains all the data should load to header and child list. I have loaded the data to header list. But I don't know how to load the data to child list. I have used this tutorial to do my expandable list view (<a href="http://www.androidhive.info/2013/07/android-expandable-list-view-tutorial/" rel="nofollow noreferrer">http://www.androidhive.info/2013/07/android-expandable-list-view-tutorial/</a>). </p>
  
  <p>Can anyone guide me how can I achieve it please. Any help will be appreciated. </p>
  
  <p><strong>UPDATED</strong> </p>
  
  <p>ProductAdapter.java</p>
  
  <pre><code>public class ProductAdapter extends BaseExpandableListAdapter {
  
      private Context _context;
      private List&lt;String&gt; _listDataHeader;
      private LayoutInflater mInflater;
      private boolean mShowQuantity;
      private HashMap&lt;String, List&lt;String&gt;&gt; _listDataChild;
  
      public ProductAdapter(Context context, List&lt;String&gt; listDataHeader,
              LayoutInflater inflater,
              HashMap&lt;String, List&lt;String&gt;&gt; listChildData, boolean showQuantity) {
          this._context = context;
          this._listDataHeader = listDataHeader;
          mInflater = inflater;
          mShowQuantity = showQuantity;
          this._listDataChild = listChildData;
      }
  
      @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.cart_list_item, null);
          }
  
          TextView txtListChild = (TextView) convertView
                  .findViewById(R.id.lblListItem);
  
          txtListChild.setText(childText);
          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);
          if (convertView == null) {
              LayoutInflater infalInflater = (LayoutInflater) this._context
                      .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
              convertView = infalInflater.inflate(R.layout.cart_list_group, null);
          }
  
          TextView lblListHeader = (TextView) convertView
                  .findViewById(R.id.lblListHeader);
          lblListHeader.setTypeface(null, Typeface.BOLD);
          lblListHeader.setText(headerTitle);
  
          return convertView;
      }
  
      @Override
      public boolean hasStableIds() {
          return false;
      }
  
      @Override
      public boolean isChildSelectable(int groupPosition, int childPosition) {
          return true;
      }
  
  }
  </code></pre>
  
  <p>Shoppingcart.java</p>
  
  <pre><code>mCartList = ShoppingCartHelper.getCartList();
  
  HashMap&lt;String, List&lt;String&gt;&gt; listDataChild = new HashMap&lt;String, List&lt;String&gt;&gt;();
  List&lt;String&gt; listDataHeader = new ArrayList&lt;String&gt;();
  
  List&lt;String&gt; listdescription = new ArrayList&lt;String&gt;();
  List&lt;String&gt; listcrust = new ArrayList&lt;String&gt;();
  List&lt;String&gt; listsize = new ArrayList&lt;String&gt;();
  List&lt;String&gt; listDescriptionOne = new ArrayList&lt;String&gt;();
  List&lt;String&gt; listDescriptionTwo = new ArrayList&lt;String&gt;();
  List&lt;String&gt; listDescriptionHalf = new ArrayList&lt;String&gt;();
  List&lt;String&gt; listExtracheese = new ArrayList&lt;String&gt;();
  
  String description;
  String crust;
  
  // Make sure to clear the selections
  for (int i = 0; i &lt; mCartList.size(); i++) {
  
      mCartList.get(i).selected = false;
      hot_number = mCartList.size();
  
      if (mCartList.get(i).description != null
              &amp;&amp; !mCartList.get(i).description.isEmpty()) {
          description = mCartList.get(i).description;
  
          listdescription.add(description);
          System.out.println("listdescription = " + listdescription);
      }
  
      if (mCartList.get(i).crust != null
              &amp;&amp; !mCartList.get(i).crust.isEmpty()) {
          crust = mCartList.get(i).crust;
  
          listcrust.add(crust);
          System.out.println("listcrust = " + listcrust);
      }
  
  }
  
  listDataChild.put("listcrust", listcrust);
  
  listDataHeader.addAll(listdescription);
  
  // get the listview
  expListView = (ExpandableListView) findViewById(R.id.lvExp);
  
  mProductAdapter = new ProductAdapter(this, listDataHeader,
          getLayoutInflater(), listDataChild, true);      
  
  // setting list adapter
  expListView.setAdapter(mProductAdapter);
  </code></pre>
  
  <p>}</p>
  
  <p>Screenshot</p>
  
  <p><img src="https://i.stack.imgur.com/nm3kb.png" alt="enter image description here"></p>