title: issue in Multilevel expandable data set in android
body: <p>i have multilevel expandable listview below is my code</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
  public static final int FIRST_LEVEL_COUNT = 6;
  public static final int SECOND_LEVEL_COUNT = 4;
  public static final int THIRD_LEVEL_COUNT = 20;
  private ExpandableListView expandableListView;
  
  private ArrayList&lt;Product&gt; pProductArrayList;
  private ArrayList&lt;Product.SubCategory&gt; pSubItemArrayList;
  private ArrayList&lt;Product.SubCategory&gt; pSubItemArrayList2;
  
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      expandableListView = (ExpandableListView) findViewById(R.id.mainList);
  
      ArrayList&lt;Product.SubCategory.ItemList&gt; mItemListArray = new ArrayList&lt;Product.SubCategory.ItemList&gt;();
      mItemListArray.add(new Product.SubCategory.ItemList("Red", "20"));
      mItemListArray.add(new Product.SubCategory.ItemList("Blue", "50"));
      mItemListArray.add(new Product.SubCategory.ItemList("Red", "20"));
      mItemListArray.add(new Product.SubCategory.ItemList("Blue", "50"));
  
      ArrayList&lt;Product.SubCategory.ItemList&gt; mItemListArray2 = new ArrayList&lt;Product.SubCategory.ItemList&gt;();
      mItemListArray2.add(new Product.SubCategory.ItemList("Pant", "2000"));
      mItemListArray2.add(new Product.SubCategory.ItemList("Shirt", "1000"));
      mItemListArray2.add(new Product.SubCategory.ItemList("Pant", "2000"));
      mItemListArray2.add(new Product.SubCategory.ItemList("Shirt", "1000"));
      mItemListArray2.add(new Product.SubCategory.ItemList("Pant", "2000"));
      mItemListArray2.add(new Product.SubCategory.ItemList("Shirt", "1000"));
  
  
      /**
       *
       */
      pSubItemArrayList = new ArrayList&lt;Product.SubCategory&gt;();
      pSubItemArrayList2 = new ArrayList&lt;Product.SubCategory&gt;();
      pSubItemArrayList.add(new Product.SubCategory("Color", mItemListArray));
      pSubItemArrayList2.add(new Product.SubCategory("Cloths", mItemListArray2));
      pSubItemArrayList.add(new Product.SubCategory("Color", mItemListArray));
      pSubItemArrayList2.add(new Product.SubCategory("Cloths", mItemListArray2));
      /**
       *
       */
  
      pProductArrayList = new ArrayList&lt;Product&gt;();
      pProductArrayList.add(new Product("Emotions", pSubItemArrayList));
      pProductArrayList.add(new Product("Garments", pSubItemArrayList2));
      Log.d("pSubItemArrayList2", String.valueOf(pSubItemArrayList2.size()));
      expandableListView.setAdapter(new ParentLevel(this, pProductArrayList, pSubItemArrayList, pSubItemArrayList2));
  
      // First level items in the ExpandableListView
      expandableListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
          @Override
          public boolean onGroupClick(ExpandableListView eListView, View view, int groupPosition,
                                      long id) {
              // TODO: whatever you need
              return false /* or true depending on what you need */;
          }
      });
  
      // Second level items in the ExpandableListView
      ExpandableListView.OnGroupClickListener grpLst = new ExpandableListView.OnGroupClickListener() {
          @Override
          public boolean onGroupClick(ExpandableListView eListView, View view, int groupPosition,
                                      long id) {
              // TODO: whatever you need
              return false /* or true depending on what you need */;
          }
      };
  
      // Third (and last) level items in the ExpandableListView
      ExpandableListView.OnChildClickListener childLst = new ExpandableListView.OnChildClickListener() {
          @Override
          public boolean onChildClick(ExpandableListView eListView, View view, int groupPosition,
                                      int childPosition, long id) {
              // TODO: whatever you need
              return false /* or true depending on what you need */;
          }
      };
  
      ExpandableListView.OnGroupExpandListener grpExpLst = new ExpandableListView.OnGroupExpandListener() {
          @Override
          public void onGroupExpand(int groupPosition) {
              /* this one is not required of course, you can delete it from the RootAdapter Constructor
               * it is just an example as to how to implement Listeners on the second level items */
          }
      };
  }
  
  public class ParentLevel extends BaseExpandableListAdapter {
  
      private Context context;
  
      private ArrayList&lt;Product&gt; pProductArrayList;
      private ArrayList&lt;Product.SubCategory&gt; pSubItemArrayList;
      private ArrayList&lt;Product.SubCategory&gt; pSubItemArrayList2;
  
      public ParentLevel(Context context) {
          this.context = context;
      }
  
      public ParentLevel(MainActivity mainActivity, ArrayList&lt;Product&gt; pProductArrayList, ArrayList&lt;Product.SubCategory&gt; pSubItemArrayList, ArrayList&lt;Product.SubCategory&gt; pSubItemArrayList2) {
          this.context = mainActivity;
          this.pProductArrayList = pProductArrayList;
          this.pSubItemArrayList = pSubItemArrayList;
          this.pSubItemArrayList2 = pSubItemArrayList2;
  
      }
  
      @Override
      public Object getChild(int arg0, int arg1) {
          return arg1;
      }
  
      @Override
      public long getChildId(int groupPosition, int childPosition) {
          return childPosition;
      }
  
      @Override
      public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
          SecondLevelExpandableListView secondLevelELV = new SecondLevelExpandableListView(MainActivity.this);
          secondLevelELV.setAdapter(new SecondLevelAdapter(context, groupPosition, childPosition));
          secondLevelELV.setGroupIndicator(null);
          return secondLevelELV;
      }
  
      @Override
      public int getChildrenCount(int groupPosition) {
          return pSubItemArrayList.size();
      }
  
      @Override
      public Object getGroup(int groupPosition) {
          return groupPosition;
      }
  
      @Override
      public int getGroupCount() {
          return pProductArrayList.size();
      }
  
      @Override
      public long getGroupId(int groupPosition) {
          return groupPosition;
      }
  
      @Override
      public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
          if (convertView == null) {
              LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
              convertView = inflater.inflate(R.layout.row_first, null);
              TextView text = (TextView) convertView.findViewById(R.id.eventsListEventRowText);
              text.setText(pProductArrayList.get(groupPosition).getpName());
          }
          return convertView;
      }
  
      @Override
      public boolean hasStableIds() {
          return true;
      }
  
      @Override
      public boolean isChildSelectable(int groupPosition, int childPosition) {
          return true;
      }
  }
  
  public class SecondLevelExpandableListView extends ExpandableListView {
  
      public SecondLevelExpandableListView(Context context) {
          super(context);
      }
  
      protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
          //999999 is a size in pixels. ExpandableListView requires a maximum height in order to do measurement calculations.
          heightMeasureSpec = MeasureSpec.makeMeasureSpec(999999, MeasureSpec.AT_MOST);
          super.onMeasure(widthMeasureSpec, heightMeasureSpec);
      }
  }
  
  public class SecondLevelAdapter extends BaseExpandableListAdapter {
  
      private Context context;
      int group;
      int child;
  
      public SecondLevelAdapter(Context context) {
          this.context = context;
      }
  
      public SecondLevelAdapter(Context context, int groupPosition, int childPosition) {
          this.context = context;
          this.group = groupPosition;
          this.child = childPosition;
      }
  
      @Override
      public Object getGroup(int groupPosition) {
          return groupPosition;
      }
  
      @Override
      public int getGroupCount() {
          return 1;
      }
  
      @Override
      public long getGroupId(int groupPosition) {
          return groupPosition;
      }
  
      @Override
      public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
          if (convertView == null) {
              LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
              convertView = inflater.inflate(R.layout.row_third, null);
              TextView text = (TextView) convertView.findViewById(R.id.eventsListEventRowText);
              final String catName = pProductArrayList.get(group).getmSubCategoryList().get(child).getpSubCatName();
  
              text.setText(catName);
          }
          return convertView;
      }
  
      @Override
      public Object getChild(int groupPosition, int childPosition) {
          return childPosition;
      }
  
      @Override
      public long getChildId(int groupPosition, int childPosition) {
          return childPosition;
      }
  
      @Override
      public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
          if (convertView == null) {
              LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
              convertView = inflater.inflate(R.layout.row_second, null);
              TextView text = (TextView) convertView.findViewById(R.id.eventsListEventRowText);
              text.setText(pProductArrayList.get(group).getmSubCategoryList().get(child).getmItemListArray().get(childPosition).getItemName() + " " + pProductArrayList.get(group).getmSubCategoryList().get(child).getmItemListArray().get(childPosition).getItemPrice());
  
          }
          return convertView;
      }
  
      @Override
      public int getChildrenCount(int groupPosition) {
          return pSubItemArrayList2.size();
      }
  
      @Override
      public boolean hasStableIds() {
          return true;
      }
  
      @Override
      public boolean isChildSelectable(int groupPosition, int childPosition) {
          return true;
           }
        }
     }
  </code></pre>
  
  <p>when i run above code in Garments option inside Cloth only 2 items is display, it should display 6 items at last level so any idea how can i solve this ? your all suggestions are appreciable. </p>
  
  <p><strong>EDIT</strong></p>
  
  <pre><code>public class Product {
  
  private String pName;
  
  private ArrayList&lt;SubCategory&gt; mSubCategoryList;
  
  public Product(String pName, ArrayList&lt;SubCategory&gt; mSubCategoryList) {
      super();
      this.pName = pName;
      this.mSubCategoryList = mSubCategoryList;
  }
  
  public String getpName() {
      return pName;
  }
  
  public void setpName(String pName) {
      this.pName = pName;
  }
  
  public ArrayList&lt;SubCategory&gt; getmSubCategoryList() {
      return mSubCategoryList;
  }
  
  public void setmSubCategoryList(ArrayList&lt;SubCategory&gt; mSubCategoryList) {
      this.mSubCategoryList = mSubCategoryList;
  }
  
  /**
   * 
   * second level item
   * 
   */
  
  public static class SubCategory {
  
      private String pSubCatName;
      private ArrayList&lt;ItemList&gt; mItemListArray;
  
      public SubCategory(String pSubCatName,
              ArrayList&lt;ItemList&gt; mItemListArray) {
          super();
          this.pSubCatName = pSubCatName;
          this.mItemListArray = mItemListArray;
      }
  
      public String getpSubCatName() {
          return pSubCatName;
      }
  
      public void setpSubCatName(String pSubCatName) {
          this.pSubCatName = pSubCatName;
      }
  
      public ArrayList&lt;ItemList&gt; getmItemListArray() {
          return mItemListArray;
      }
  
      public void setmItemListArray(ArrayList&lt;ItemList&gt; mItemListArray) {
          this.mItemListArray = mItemListArray;
      }
  
      /**
       * 
       * third level item
       * 
       */
      public static class ItemList {
  
          private String itemName;
          private String itemPrice;
  
          public ItemList(String itemName, String itemPrice) {
              super();
              this.itemName = itemName;
              this.itemPrice = itemPrice;
          }
  
          public String getItemName() {
              return itemName;
          }
  
          public void setItemName(String itemName) {
              this.itemName = itemName;
          }
  
          public String getItemPrice() {
              return itemPrice;
          }
  
          public void setItemPrice(String itemPrice) {
              this.itemPrice = itemPrice;
             }
  
           }
  
        }
  
     }
  </code></pre>
  
  <p><strong>ITEM CLICK NOT WORKING</strong></p>
  
  <pre><code>// First level items in the ExpandableListView
      expandableListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
          @Override
          public boolean onGroupClick(ExpandableListView eListView, View view, int groupPosition,
                                      long id) {
              // TODO: whatever you need
              Log.d("Grop ",pProductArrayList.get(groupPosition).getpName());
              return false /* or true depending on what you need */;
          }
      });
  
      // Second level items in the ExpandableListView
      ExpandableListView.OnGroupClickListener grpLst = new ExpandableListView.OnGroupClickListener() {
          @Override
          public boolean onGroupClick(ExpandableListView eListView, View view, int groupPosition,
                                      long id) {
              // TODO: whatever you need
              Log.d("Sub Grop ",pProductArrayList.get(groupPosition).getmSubCategoryList().get(groupPosition).getpSubCatName());
  
  
              return false /* or true depending on what you need */;
          }
      };
  
      // Third (and last) level items in the ExpandableListView
      ExpandableListView.OnChildClickListener childLst = new ExpandableListView.OnChildClickListener() {
          @Override
          public boolean onChildClick(ExpandableListView eListView, View view, int groupPosition,
                                      int childPosition, long id) {
              Log.d("Child Grop ",pProductArrayList.get(groupPosition).getmSubCategoryList().get(groupPosition).getmItemListArray().get(childPosition).getItemName()+" "+pProductArrayList.get(groupPosition).getmSubCategoryList().get(groupPosition).getmItemListArray().get(childPosition).getItemPrice());
  
              // TODO: whatever you need
              return false /* or true depending on what you need */;
          }
      };
  
      ExpandableListView.OnGroupExpandListener grpExpLst = new ExpandableListView.OnGroupExpandListener() {
          @Override
          public void onGroupExpand(int groupPosition) {
          /* this one is not required of course, you can delete it from the RootAdapter Constructor
           * it is just an example as to how to implement Listeners on the second level items */
          }
      };
  </code></pre>