title: ExpandableListview Like TreeView Android
body: <p>Hey people I'm Implementing <code>TreeView</code> using <code>ExpandableListView</code>. But I have some measure problem that I unfortunately can't solve it. </p>
  
  <p>Here's ScreenShots of the problem:</p>
  
  <blockquote>
    <p><img src="https://i.stack.imgur.com/KpTeL.png" alt="This Image shows Children of Shawshank Redemption"></p>
    
    <p><img src="https://i.stack.imgur.com/OV3A4.png" alt="I this one children of Conjuring is visible but 2 childs from Shawshank disapears under Godfather"></p>
  </blockquote>
  
  <p>You can see that there are problems in measuring. As long as I'm new to Android I don't really understand <code>onMeasure()</code> method. 
  I have 1 <code>ExpandableListView</code> and in it's <code>getChildView()</code> i return <code>CustomExapndableListView</code>-s.</p>
  
  <p>Here's code:</p>
  
  <p><strong>ExpandableListAdapter :</strong> </p>
  
  <pre><code>public class ExpandableListAdapter extends BaseExpandableListAdapter {
  private Context context;
  private List&lt;String&gt; listDataHeader;
  private HashMap&lt;String, List&lt;String&gt;&gt; listDataChild;
  
  public ExpandableListAdapter (Context context, List&lt;String&gt; listDataHeader, HashMap&lt;String, List&lt;String&gt;&gt; listChildData) {
      this.context = context;
      this.listDataHeader = listDataHeader;
      this.listDataChild = listChildData;
  }
  
  @Override
  public int getGroupCount() {
      return this.listDataHeader.size();
  }
  
  @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 Object getChild(int groupPosition, int childPosition) {
      return this.listDataChild.get(this.listDataHeader.get(groupPosition)).get(childPosition);
  }
  
  @Override
  public long getGroupId(int groupPosition) {
      return groupPosition;
  }
  
  @Override
  public long getChildId(int groupPosition, int childPosition) {
      return childPosition;
  }
  
  @Override
  public boolean hasStableIds() {
      return false;
  }
  
  @Override
  public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
      String headerTitle = (String) getGroup(groupPosition);
      Log.i("Header: ", " " + headerTitle);
      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);
  
      return convertView;
  }
  
  @Override
  public View getChildView(int groupPosition, 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);*/
  
      String childText = (String) getChild(groupPosition, childPosition);
      if(listDataChild.containsKey(childText)){
          Log.i("Child", "" + childText);
          CustomExpandableListView explv = new CustomExpandableListView(context);
        //  explv.setRows(calculateRowCount((String)getGroup(groupPosition), null));
        //  ChildLayerExpandableListAdapter adapter = new ChildLayerExpandableListAdapter(context, listDataChild.get(getGroup(groupPosition)), listDataChild);
          Log.i("Opaaaa:", " " + getGroup(groupPosition));
          List&lt;String&gt; newHeaders = new ArrayList &lt;String&gt;();
          newHeaders.add(childText);
          // listDataChild.get(getGroup(groupPosition))
          ExpandableListAdapter adapter = new ExpandableListAdapter(context, newHeaders, listDataChild);
          explv.setAdapter(adapter);
          explv.setGroupIndicator(null);
          convertView = explv;
          convertView.setPadding(20, 0, 0, 0);
      }else{
        //  if(convertView == null) {
              LayoutInflater infalInflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
              convertView = infalInflater.inflate(R.layout.list_item, null);
     //     }
  
          Log.i("Else:", " " + childText);
  
          TextView txtListChild = (TextView) convertView.findViewById(R.id.lblListItem);
  
          txtListChild.setText(childText);
  
          convertView.setPadding(20, 0, 0, 0);
      }
  
      return convertView;
  }
  
  private int calculateRowCount (String key, ExpandableListView listView) {
      int groupCount = listDataChild.get(key).size();
      int rowCtr = 0;
      for(int i = 0; i &lt; groupCount; i++) {
          rowCtr++;
          if( (listView != null) &amp;&amp; (listView.isGroupExpanded(i)))
              rowCtr += listDataChild.get(listDataChild.get(key).get(i)).size() - 1;
      }
      return rowCtr;
  }
  
  @Override
  public boolean isChildSelectable(int groupPosition, int childPosition) {
      return true;
  }
  </code></pre>
  
  <p><strong>CustomExpandableListView :</strong></p>
  
  <pre><code>    public class CustomExpandableListView extends ExpandableListView {
  
      private static final int HEIGHT = 20;
      private int rows;
  
      public void setRows(int rows) {
          this.rows = rows;
      }
  
      public CustomExpandableListView(Context context) {
          super(context);
      }
  
      public CustomExpandableListView(Context context, AttributeSet attrs) {
          super(context, attrs);
      }
  
      @Override
      protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
          heightMeasureSpec = MeasureSpec.makeMeasureSpec(500, MeasureSpec.AT_MOST);
          super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        //  setMeasuredDimension(getMeasuredWidth(), rows * HEIGHT);
      }
  }
  </code></pre>
  
  <p>What I want to do is,when I expand the view, I want all children to be shown and I could just scroll down the <code>ListView</code>. Right now some children are hidden under different children.</p>
  
  <p>Thanks in Advance for your Help.</p>