title: Multilevel Expandable Listview
body: <p>I'm trying to add values into the parent groupPosition[0] particularly. But its reflecting to all the groupPositions of parent list item. Plesae help me guys.</p>
  
  <pre><code>   public class MainActivity extends Activity
      {
      ExpandableListView explvlist;
      ArrayList&lt;String&gt; StringArray = new ArrayList&lt;String&gt;();
      ArrayList&lt;String&gt; StringArrayChild=new ArrayList&lt;String&gt;();
      @Override
      public void onCreate(Bundle savedInstanceState)
      {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          ArrayValueAddFunction();
          ArrayValueAddFunction_Level2();
          explvlist = (ExpandableListView)findViewById(R.id.ParentLevel);
          explvlist.setAdapter(new ParentLevel(StringArray)); 
      }
      private void ArrayValueAddFunction_Level2() {
          StringArrayChild.add("Level1 item1");
          StringArrayChild.add("Level1 item2");
          StringArrayChild.add("Level1 item3");
          StringArrayChild.add("Level1 item4");
          StringArrayChild.add("Level1 item5");
          StringArrayChild.add("Level1 item6");
      }
      private void ArrayValueAddFunction() {
          StringArray.add("ONE");
          StringArray.add("TWO");
          StringArray.add("THREE");
          StringArray.add("FOUR");
          StringArray.add("FIVE");
          StringArray.add("SIX");
      }
      public class ParentLevel extends BaseExpandableListAdapter {
          ArrayList&lt;String&gt; StringArray = new ArrayList&lt;String&gt;();
          private Context context;
          public ParentLevel(ArrayList&lt;String&gt; stringArray) {
              this.StringArray=stringArray;
          }
          @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) {
              CustExpListview SecondLevelexplv = new CustExpListview(MainActivity.this);
  
                  SecondLevelexplv.setAdapter(new SecondLevelAdapter());
                  SecondLevelexplv.setGroupIndicator(null);
                  return SecondLevelexplv;
          }
          @Override
          public int getChildrenCount(int groupPosition) {
              return 3;
          }
          @Override
          public Object getGroup(int groupPosition) {
              return groupPosition;
          }
          @Override
          public int getGroupCount() {
              return StringArray.size();
          }
          @Override
          public long getGroupId(int groupPosition) {
              return groupPosition;
          }
          @Override
          public View getGroupView(int groupPosition, boolean isExpanded,
                                          View convertView, ViewGroup parent) {
              TextView tv = new TextView(MainActivity.this);
              if (groupPosition==0) {
                  tv.append(StringArray.get(0));
              }else if (groupPosition==1){
                  tv.append(StringArray.get(1));
              }else if (groupPosition==2){
                  tv.append(StringArray.get(2));
              }else if (groupPosition==3){
                  tv.append(StringArray.get(3));
              }else if (groupPosition==4){
                  tv.append(StringArray.get(4));
              }else if (groupPosition==5){
                  tv.append(StringArray.get(5));
              }
              return tv;
          }
          @Override
          public boolean hasStableIds() {
              return true;
          }
          @Override
          public boolean isChildSelectable(int groupPosition, int childPosition) {
              return true;
          }
          public class SecondLevelAdapter extends BaseExpandableListAdapter
          {
  
              @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)
              {
                  TextView tv = new TextView(MainActivity.this);
                  tv.setText("child");
                  tv.setPadding(15, 5, 5, 5);
                  tv.setBackgroundColor(Color.GRAY);
                  tv.setLayoutParams(new ListView.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));
                  return tv;
              }
              @Override
              public int getChildrenCount(int groupPosition) {
                  return 6;
              }
              @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)
              {
                  TextView tv = new TextView(MainActivity.this);
                  if (groupPosition==0) {
                      tv.append(StringArrayChild.get(0));
                  }else if (groupPosition==1){
                      tv.append(StringArrayChild.get(1));
                  }else if (groupPosition==2){
                      tv.append(StringArrayChild.get(2));
                  }else if (groupPosition==3){
                      tv.append(StringArrayChild.get(3));
                  }else if (groupPosition==4){
                      tv.append(StringArrayChild.get(4));
                  }else if (groupPosition==5){
                      tv.append(StringArrayChild.get(5));
                  }
                  tv.setPadding(12, 7, 7, 7);
                  tv.setBackgroundColor(Color.YELLOW);
                  return tv;
              }
  
              @Override
              public boolean hasStableIds() {
                  // TODO Auto-generated method stub
                  return true;
              }
  
              @Override
              public boolean isChildSelectable(int groupPosition, int childPosition) {
                  // TODO Auto-generated method stub
                  return true;
              }
  
          }
      }
      }
  </code></pre>
  
  <p>CustExpListview</p>
  
  <pre><code>     class CustExpListview extends ExpandableListView
       {
      int intGroupPosition, intChildPosition, intGroupid;
      public CustExpListview(Context context) {
          super(context);
      }
      protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
          widthMeasureSpec = MeasureSpec.makeMeasureSpec(960, MeasureSpec.AT_MOST);
          heightMeasureSpec = MeasureSpec.makeMeasureSpec(600, MeasureSpec.AT_MOST);
          super.onMeasure(widthMeasureSpec, heightMeasureSpec);
      }
  }
  </code></pre>
  
  <p>Layout design with expandableListView</p>
  
  <pre><code>     &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:orientation="vertical"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      tools:context=".MainActivity"&gt;
      &lt;ExpandableListView
          android:layout_width="fill_parent"
          android:id="@+id/ParentLevel"
          android:groupIndicator="@null"
          android:layout_height="fill_parent"&gt;
      &lt;/ExpandableListView&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>The image given below is the output, all the items are coming into all the positions, but i need to put position[0], but its reflecting to all the groupPositins of parent list</p>
  
  <p><a href="https://i.stack.imgur.com/zkMZJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zkMZJ.png" alt="enter image description here"></a></p>