title: remove child item from expandable listview
body: <p>I'm currently trying to create a button as a child item within a listview when the parent item is clicked, and then remove the button from the old parent item when a new parent is clicked and add the button as a child to the new parent item. </p>
  
  <p>The main issue seems to come when attempting to delete the button from the old parent item.</p>
  
  <p>Below is an example of before and after.  </p>
  
  <p>ListView: Before (Parent 1 clicked)</p>
  
  <hr>
  
  <p>Parent Object 1</p>
  
  <hr>
  
  <p>child1</p>
  
  <hr>
  
  <p>[button]</p>
  
  <hr>
  
  <p>Parent Object 2</p>
  
  <hr>
  
  <p>child2</p>
  
  <hr>
  
  <p>Listview After: (Parent 2 clicked)</p>
  
  <hr>
  
  <p>Parent Object 1</p>
  
  <hr>
  
  <p>child1</p>
  
  <hr>
  
  <p>Parent Object 2</p>
  
  <hr>
  
  <p>child2</p>
  
  <hr>
  
  <p>[button]</p>
  
  <p>The button is dynamically created without any issue when the first item is clicked.  However it seems to have issues deleting the button from the listview when a new parent is clicked.</p>
  
  <p>Below is my code and  error log.  If more information is needed please request and I will provide the full source.</p>
  
  <pre><code>public void initParentListViewListeners(){
  
      listView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
  
          @Override
          public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
              int lastChild = childArray.get(groupPosition).getNumOfChildren() - 1;
  
              if (lastParentClicked != null &amp;&amp; listAdapter.getChild(groupPosition, lastChild) != "Button") {
                  int size = childArray.get(lastParentPosition).getNumOfChildren();
                  //Remove button from old ArrayList
                  childArray.get(lastParentPosition).getChildArray().remove(size - 1);
                  listAdapter.notifyDataSetChanged();
              }
              if (listAdapter.getChild(groupPosition, lastChild) != "Button") {
                  //Add Button to end of ArrayList
                  childArray.get(groupPosition).getChildArray().add("Button");
                  lastParentClicked = childArray.get(groupPosition).getChildName();
                  lastParentPosition = groupPosition;
                  listAdapter.notifyDataSetChanged();
              }
  
              return false;
          }
      });
  }
  </code></pre>
  
  <p>List Adapter Class:
  Marked is where the error is occuring</p>
  
  <pre><code>public class ExpandableListAdapter extends BaseExpandableListAdapter {
  
      private Context context;
      private ArrayList&lt;ChildObject&gt; listDataHeader;
  
      public ExpandableListAdapter(Context context, ArrayList&lt;ChildObject&gt; listDataHeader){
          this.context = context;
          this.listDataHeader = listDataHeader;
      }
  
      @Override
      public String getChild(int groupPosition, int childPosition){
          ArrayList&lt;String&gt; setList = listDataHeader.get(groupPosition).getChildArray();
          return setList.get(childPosition);
      }
  
      @Override
      public long getChildId(int groupPosition, int childPosition)
      {
          return childPosition;
      }
  
      @Override
      public View getChildView(int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent){
          String childText = (String)getChild(groupPosition, childPosition);
  
          if(convertView == null){
              LayoutInflater inflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
              if(getChild(groupPosition, childPosition) == "Button"){
                  convertView = inflater.inflate(R.layout.parent_object_add_child, null);
              }
              else{
                  convertView = inflater.inflate(R.layout.parent_item_child, null);
              }
          }
  
          TextView txtListChild = (TextView) convertView.findViewById(R.id.childObjContents);
          /******** Where error is happening ***********/
          if(getChild(groupPosition, childPosition) != "Button"){
              Log.d(getClass().getSimpleName(), getChild(groupPosition, childPosition));
              txtListChild.setText(childText);
          }
  
          return convertView;
      }
  
      @Override
      public int getChildrenCount(int groupPosition){
          ArrayList&lt;String&gt; setList = listDataHeader.get(groupPosition).getChildArray();
          return setList.size();
      }
  
      @Override
      public Object getGroup(int groupPosition) {
          return  listDataHeader.get(groupPosition);
      }
  
      @Override
      public int getGroupCount(){
          return listDataHeader.size();
      }
  
      @Override
      public long getGroupId(int groupPosition){
          return groupPosition;
      }
  
      @Override
      public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent){
          String exerciseTitle = listDataHeader.get(groupPosition).getChildName();
  
          if(convertView == null){
              LayoutInflater infalInflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
              convertView = infalInflater.inflate(R.layout.parent_item_header, null);
          }
  
          TextView lblListHeader = (TextView) convertView.findViewById(R.id.parentListHeader);
          lblListHeader.setTypeface(null, Typeface.BOLD);
          lblListHeader.setText(exerciseTitle);
  
          return convertView;
      }
  
      @Override
      public boolean hasStableIds() {
          return false;
      }
  
      @Override
      public boolean isChildSelectable(int groupPosition, int childPostition) {
          return true;
      }
  
  
  }
  </code></pre>
  
  <p>Error Log:</p>
  
  <pre><code>11-15 22:03:52.896    2651-2651/myapplication.android.commonsware.com.removelistviewitem E/AndroidRuntime﹕ FATAL EXCEPTION: main
      Process: myapplication.android.commonsware.com.removelistviewitem, PID: 2651
      java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
              at myapplication.android.commonsware.com.removelistviewitem.ExpandableListAdapter.getChildView(ExpandableListAdapter.java:54)
              at android.widget.ExpandableListConnector.getView(ExpandableListConnector.java:451)
              at android.widget.AbsListView.obtainView(AbsListView.java:2347)
              at android.widget.ListView.makeAndAddView(ListView.java:1864)
              at android.widget.ListView.fillDown(ListView.java:698)
              at android.widget.ListView.fillSpecific(ListView.java:1356)
              at android.widget.ListView.layoutChildren(ListView.java:1651)
              at android.widget.AbsListView.onLayout(AbsListView.java:2151)
              at android.view.View.layout(View.java:15671)
              at android.view.ViewGroup.layout(ViewGroup.java:5038)
              at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703)
              at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1557)
              at android.widget.LinearLayout.onLayout(LinearLayout.java:1466)
              at android.view.View.layout(View.java:15671)
              at android.view.ViewGroup.layout(ViewGroup.java:5038)
              at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1076)
              at android.view.View.layout(View.java:15671)
              at android.view.ViewGroup.layout(ViewGroup.java:5038)
              at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
              at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
              at android.view.View.layout(View.java:15671)
              at android.view.ViewGroup.layout(ViewGroup.java:5038)
              at android.support.v7.internal.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:437)
              at android.view.View.layout(View.java:15671)
              at android.view.ViewGroup.layout(ViewGroup.java:5038)
              at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
              at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
              at android.view.View.layout(View.java:15671)
              at android.view.ViewGroup.layout(ViewGroup.java:5038)
              at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703)
              at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1557)
              at android.widget.LinearLayout.onLayout(LinearLayout.java:1466)
              at android.view.View.layout(View.java:15671)
              at android.view.ViewGroup.layout(ViewGroup.java:5038)
              at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
              at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
              at android.view.View.layout(View.java:15671)
              at android.view.ViewGroup.layout(ViewGroup.java:5038)
              at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2086)
              at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1843)
              at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1061)
              at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5885)
              at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
              at android.view.Choreographer.doCallbacks(Choreographer.java:580)
              at android.view.Choreographer.doFrame(Choreographer.java:550)
              at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
              at android.os.Handler.handleCallback(Handler.java:739)
              at android.os.Handler.dispatchMessage(Handler.java:95)
              at android.os.Looper.loop(Looper.java:135)
              at android.app.ActivityThread.main(ActivityThread.java:5257)
              at java.lang.reflect.Method.invoke(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:372)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
  11-15 22:03:57.380    2651-2651/? I/Process﹕ Sending signal. PID: 2651 SIG: 9
  </code></pre>