title: Expandablelistview Adapter Not Working Properly
body: <p>I firstly use ExpandableListView view in Android. I want groupviews to have different layouts or items in ExpandableView. Childs consist of spinners, textviews, edittexts.</p>
  
  <p>My problem is when expanding groups, correct layouts dont inflate or the code crashes because of null pointer exception mostly cause spinners. Some codes samples are below</p>
  
  <p>ExpandableListAdapter.java</p>
  
  <pre><code>    @Override
  public View getChildView(int groupPosition, final int childPosition,
          boolean isLastChild, View convertView, ViewGroup parent) {
  
      View v = null;
      int itemId = (int) getChildId(groupPosition, childPosition);
  
      if(convertView==null){
          switch (itemId) {
              case 6: convertView = li.inflate(R.layout.expand_akis,null);
                      v = akiskan(convertView);
                  break;
              case 9: convertView = li.inflate(R.layout.expand_kapasite,null);
                  break;
              case 11:convertView = li.inflate(R.layout.expand_kapasite2,null);
                  break;
              case 12:convertView = li.inflate(R.layout.expand_evapohava,null);
                  break;
              case 14:convertView = li.inflate(R.layout.expand_evapohava,null);
                  break;
              case 15:
                  break;
              case 18:
                  break;
              default:
                  break;
          }
  
      }
      switch (itemId) {
      case 6: v = akiskan(convertView);
          break;
      case 9: v = kapasite(convertView, childPosition);
          break;
      case 11:v = kapasite(convertView, childPosition);
          break;
      case 12:v = convertView;
          break;
      case 14:v = convertView;
          break;
      case 15:
          break;
      case 18:
          break;
      default:
          break;
      }
  
      return v;
  }
  
  private View kapasite(View convertView, int childPosition) {
  
          if(childPosition == 0){
  
              EditText editKapasite = (EditText)convertView.findViewById(R.id.editNumKap);
  
              Spinner spinKapa = (Spinner) convertView.findViewById(R.id.spinKapa);
              ArrayAdapter&lt;CharSequence&gt; adapKap = ArrayAdapter.createFromResource(activity, R.array.kapasiteler, 
                      R.layout.spinnertext);
              adapKap.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
              spinKapa.setAdapter(adapKap);
          }
          else if(childPosition == 1){
              EditText editYuzdePlus = (EditText)convertView.findViewById(R.id.editYuzdePlus);
              EditText editYuzdeMin  = (EditText)convertView.findViewById(R.id.editYuzdeMin);
          }
  
      return convertView;
  }
  
  private View akiskan(View convertView) {
  
      Spinner spinAkiskan = (Spinner) convertView.findViewById(R.id.spinAkis);
      ArrayAdapter&lt;CharSequence&gt; adapAkis = ArrayAdapter.createFromResource(activity, R.array.akiskanlar, 
              R.layout.spinnertext);
      adapAkis.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
      spinAkiskan.setAdapter(adapAkis);
  
      return convertView;
  }
  </code></pre>
  
  <p>getChildId() function generates unique id according to groupPosition and childPosition</p>
  
  <p>main.xml</p>
  
  <pre><code>&lt;ExpandableListView
      android:id="@+id/expandableList"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:layout_above="@+id/detailAraButton"
      android:layout_alignParentTop="true" /&gt;
  </code></pre>
  
  <p>expand_akis.xml</p>
  
  <pre><code>  &lt;EditText
          android:layout_alignParentLeft="true"
          android:id="@+id/editNumKap"
          android:layout_width="100dp"
          android:layout_height="wrap_content"
          android:ems="10"
          android:layout_marginLeft="20dp"
          android:inputType="numberSigned" /&gt;
  
  
       &lt;Spinner
          android:layout_toRightOf="@+id/editNumKap"
          android:layout_marginLeft="20dp"
          android:id="@+id/spinKapa"
          android:layout_width="85sp"
          android:layout_height="wrap_content"
           /&gt;
  </code></pre>
  
  <p>expand_kapasite.xml</p>
  
  <pre><code> &lt;EditText
          android:layout_alignParentLeft="true"
          android:id="@+id/editNumKap"
          android:layout_width="100dp"
          android:layout_height="wrap_content"
          android:ems="10"
          android:layout_marginLeft="20dp"
          android:inputType="numberSigned" /&gt;
  
  
       &lt;Spinner
          android:layout_toRightOf="@+id/editNumKap"
          android:layout_marginLeft="20dp"
          android:id="@+id/spinKapa"
          android:layout_width="85sp"
          android:layout_height="wrap_content"
           /&gt;
  </code></pre>
  
  <p>LogCat</p>
  
  <pre><code>    02-23 14:11:21.952: E/AndroidRuntime(16384): FATAL EXCEPTION: main
  02-23 14:11:21.952: E/AndroidRuntime(16384): java.lang.NullPointerException
  02-23 14:11:21.952: E/AndroidRuntime(16384):    at com.buzcelik.tools.ExpandListAdapter.kapasite(ExpandListAdapter.java:105)
  02-23 14:11:21.952: E/AndroidRuntime(16384):    at com.buzcelik.tools.ExpandListAdapter.getChildView(ExpandListAdapter.java:76)
  02-23 14:11:21.952: E/AndroidRuntime(16384):    at android.widget.ExpandableListConnector.getView(ExpandableListConnector.java:450)
  02-23 14:11:21.952: E/AndroidRuntime(16384):    at android.widget.AbsListView.obtainView(AbsListView.java:2025)
  02-23 14:11:21.952: E/AndroidRuntime(16384):    at android.widget.ListView.makeAndAddView(ListView.java:1820)
  02-23 14:11:21.952: E/AndroidRuntime(16384):    at android.widget.ListView.fillDown(ListView.java:672)
  02-23 14:11:21.952: E/AndroidRuntime(16384):    at android.widget.ListView.fillSpecific(ListView.java:1378)
  02-23 14:11:21.952: E/AndroidRuntime(16384):    at android.widget.ListView.layoutChildren(ListView.java:1651)
  02-23 14:11:21.952: E/AndroidRuntime(16384):    at android.widget.AbsListView.onLayout(AbsListView.java:1876)
  02-23 14:11:21.952: E/AndroidRuntime(16384):    at android.view.View.layout(View.java:11425)
  02-23 14:11:21.952: E/AndroidRuntime(16384):    at android.view.ViewGroup.layout(ViewGroup.java:4232)
  02-23 14:11:21.952: E/AndroidRuntime(16384):    at android.widget.RelativeLayout.onLayout(RelativeLayout.java:925)
  02-23 14:11:21.952: E/AndroidRuntime(16384):    at android.view.View.layout(View.java:11425)
  02-23 14:11:21.952: E/AndroidRuntime(16384):    at android.view.ViewGroup.layout(ViewGroup.java:4232)
  02-23 14:11:21.952: E/AndroidRuntime(16384):    at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
  02-23 14:11:21.952: E/AndroidRuntime(16384):    at android.view.View.layout(View.java:11425)
  02-23 14:11:21.952: E/AndroidRuntime(16384):    at android.view.ViewGroup.layout(ViewGroup.java:4232)
  02-23 14:11:21.952: E/AndroidRuntime(16384):    at android.support.v4.view.ViewPager.onLayout(ViewPager.java:1589)
  02-23 14:11:21.952: E/AndroidRuntime(16384):    at android.view.View.layout(View.java:11425)
  02-23 14:11:21.952: E/AndroidRuntime(16384):    at android.view.ViewGroup.layout(ViewGroup.java:4232)
  02-23 14:11:21.952: E/AndroidRuntime(16384):    at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
  02-23 14:11:21.952: E/AndroidRuntime(16384):    at android.view.View.layout(View.java:11425)
  02-23 14:11:21.952: E/AndroidRuntime(16384):    at android.view.ViewGroup.layout(ViewGroup.java:4232)
  02-23 14:11:21.952: E/AndroidRuntime(16384):    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1628)
  02-23 14:11:21.952: E/AndroidRuntime(16384):    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1486)
  02-23 14:11:21.952: E/AndroidRuntime(16384):    at android.widget.LinearLayout.onLayout(LinearLayout.java:1399)
  02-23 14:11:21.952: E/AndroidRuntime(16384):    at android.view.View.layout(View.java:11425)
  02-23 14:11:21.952: E/AndroidRuntime(16384):    at android.view.ViewGroup.layout(ViewGroup.java:4232)
  02-23 14:11:21.952: E/AndroidRuntime(16384):    at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
  02-23 14:11:21.952: E/AndroidRuntime(16384):    at android.view.View.layout(View.java:11425)
  02-23 14:11:21.952: E/AndroidRuntime(16384):    at android.view.ViewGroup.layout(ViewGroup.java:4232)
  02-23 14:11:21.952: E/AndroidRuntime(16384):    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1509)
  02-23 14:11:21.952: E/AndroidRuntime(16384):    at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2498)
  02-23 14:11:21.952: E/AndroidRuntime(16384):    at android.os.Handler.dispatchMessage(Handler.java:99)
  02-23 14:11:21.952: E/AndroidRuntime(16384):    at android.os.Looper.loop(Looper.java:154)
  02-23 14:11:21.952: E/AndroidRuntime(16384):    at android.app.ActivityThread.main(ActivityThread.java:4944)
  02-23 14:11:21.952: E/AndroidRuntime(16384):    at java.lang.reflect.Method.invokeNative(Native Method)
  02-23 14:11:21.952: E/AndroidRuntime(16384):    at java.lang.reflect.Method.invoke(Method.java:511)
  02-23 14:11:21.952: E/AndroidRuntime(16384):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
  02-23 14:11:21.952: E/AndroidRuntime(16384):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
  02-23 14:11:21.952: E/AndroidRuntime(16384):    at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>getChild() function</p>
  
  <pre><code>   @Override
  public long getChildId(int groupPosition, int childPosition) {
      return 2*(childPosition+3+groupPosition)+groupPosition ;
  }
  </code></pre>
  
  <p>Thanks in Advance!</p>