title: Android expandable list: how to add different layout for layout groups
body: <p>My problem is while clicking on the groups at first position it shows the child properly but when I click next group item the application crashes.</p>
  
  <pre><code>@Override
  public View getChildView(final int i, int i2, boolean b, View v, ViewGroup viewGroup) {
  
      if (v==null) {
          LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          int itemType = getChildType(i, i2);
  
          int grup_pos = (int) getGroupId(i);
          switch (itemType`enter code here`) {
              case 0:
                  v = inflater.inflate(R.layout.child_contact, null);
                  Toast.makeText(context.getApplicationContext(), "position is" + grup_pos, Toast.LENGTH_SHORT).show();
                  break;
              case 1:
                  v = inflater.inflate(R.layout.child_faq_answer, null);
                  Toast.makeText(context.getApplicationContext(), "position is" + grup_pos, Toast.LENGTH_SHORT).show();
                  break;
              case 2:
                  v = inflater.inflate(R.layout.child_main_contact, null);
                  Toast.makeText(context.getApplicationContext(), "position is" + grup_pos, Toast.LENGTH_SHORT).show();
                  break;
              case 3:
                  v = inflater.inflate(R.layout.child_events_items, null);
                  Toast.makeText(context.getApplicationContext(), "position is" + grup_pos, Toast.LENGTH_SHORT).show();
                  break;
              case 4:
                  v = inflater.inflate(R.layout.child_program, null);
                  Toast.makeText(context.getApplicationContext(), "position is" + grup_pos, Toast.LENGTH_SHORT).show();
                  break;
              case 5:
                  v = inflater.inflate(R.layout.item_faq_answer, null);
                  Toast.makeText(context.getApplicationContext(), "position is" + grup_pos, Toast.LENGTH_SHORT).show();
                  break;
              case 6:
                  v = inflater.inflate(R.layout.child_program, null);
                  Toast.makeText(context.getApplicationContext(), "position is" + grup_pos, Toast.LENGTH_SHORT).show();
                  break;
          }
      }
      v.invalidate();
      return v;
  }
  </code></pre>
  
  <p><strong>This is the error what I get</strong></p>
  
  <pre><code>E/AndroidRuntime﹕ FATAL EXCEPTION: main
      java.lang.ArrayIndexOutOfBoundsException: length=2; index=2
              at android.widget.AbsListView$RecycleBin.addScrapView(AbsListView.java:6773)
              at android.widget.ListView.layoutChildren(ListView.java:1602)
              at android.widget.AbsListView.onLayout(AbsListView.java:2056)
              at android.view.View.layout(View.java:14118)
              at android.view.ViewGroup.layout(ViewGroup.java:4467)
              at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1670)
              at android.widget.LinearLayout.layoutHorizontal(LinearLayout.java:1659)
              at android.widget.LinearLayout.onLayout(LinearLayout.java:1443)
              at android.view.View.layout(View.java:14118)
              at android.view.ViewGroup.layout(ViewGroup.java:4467)
              at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1021)
              at android.view.View.layout(View.java:14118)
              at android.view.ViewGroup.layout(ViewGroup.java:4467)
              at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
              at android.view.View.layout(View.java:14118)
              at android.view.ViewGroup.layout(ViewGroup.java:4467)
              at android.support.v7.internal.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:493)
              at android.view.View.layout(View.java:14118)
              at android.view.ViewGroup.layout(ViewGroup.java:4467)
              at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
              at android.view.View.layout(View.java:14118)
              at android.view.ViewGroup.layout(ViewGroup.java:4467)
              at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1670)
              at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1528)
              at android.widget.LinearLayout.onLayout(LinearLayout.java:1441)
              at android.view.View.layout(View.java:14118)
              at android.view.ViewGroup.layout(ViewGroup.java:4467)
              at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
              at android.view.View.layout(View.java:14118)
              at android.view.ViewGroup.layout(ViewGroup.java:4467)
              at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2202)
              at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1966)
              at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1158)
              at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4914)
              at android.view.Choreographer$CallbackRecord.run(Choreographer.java:776)
              at android.view.Choreographer.doCallbacks(Choreographer.java:579)
              at android.view.Choreographer.doFrame(Choreographer.java:548)
              at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:762)
              at android.os.Handler.handleCallback(Handler.java:800)
              at android.os.Handler.dispatchMessage(Handler.java:100)
              at android.os.Looper.loop(Looper.java:194)
              at android.app.ActivityThread.main(ActivityThread.java:5371)
              at java.lang.reflect.Method.invokeNative(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:525)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
              at dalvik.system.NativeStart.main(Native Method)
  </code></pre>