Code example for ExpandableListView

Methods: collapseGroupsetOnItemClickListener, setEmptyView

-1
        throw new RuntimeException("Content has view with id attribute 'android.R.id.list' "
            + "that is not a ExpandableListView class"); 
      } 
      expandableListView = (ExpandableListView) rawListView;
      if (mEmptyView != null) {
        expandableListView.setEmptyView(mEmptyView);
      } 
    } 
    mListShown = true;
    expandableListView.setOnItemClickListener(mOnClickListener);
    if (mAdapter != null) {
      setListAdapter(mAdapter);
    } else { 
      // We are starting without an adapter, so assume we won't 
      // have our data right away and start with the progress indicator. 
      setListShown(false, false); 
    } 
    mHandler.post(mRequestFocus);
  } 
 
  @Override 
  public void onGroupExpand(int arg0) {
    // TODO Auto-generated method stub 
 
  } 
 
  @Override 
  public void onGroupCollapse(int arg0) {
    // TODO Auto-generated method stub 
 
  } 
 
  /** 
   * Callback method to be invoked when a child in this expandable list has been 
   * clicked. 
   *  
   * @param parent 
   *          The ExpandableListView where the click happened 
   * @param v 
   *          The view within the expandable list/ListView that was clicked 
   * @param groupPosition 
   *          The group position that contains the child that was clicked 
   * @param childPosition 
   *          The child position within the group 
   * @param id 
   *          he row id of the child that was clicked 
   * @return True if the click was handled 
   */ 
  @Override 
  public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
    return mAdapter.onChildClick(parent, v, groupPosition, childPosition, id);
  } 
 
   
  public void onContentChanged() { 
    View emptyView = getView().findViewById(android.R.id.empty);
    expandableListView = (ExpandableListView) getView().findViewById(android.R.id.list);
    if (expandableListView == null) {
      throw new RuntimeException("Your content must have a ExpandableListView whose id attribute is "
          + "'android.R.id.list'"); 
    } 
    if (emptyView != null) {
      expandableListView.setEmptyView(emptyView);
    } 
    expandableListView.setOnChildClickListener(this);
    expandableListView.setOnGroupExpandListener(this);
    expandableListView.setOnGroupCollapseListener(this);
    expandableListView.setOnItemLongClickListener(this);
 
    if (mFinishedStart) {
      setListAdapter(mAdapter);
    } 
    mFinishedStart = true;
  } 
 
  @Override 
  public void setSelectedGroup(int groupPosition) {
    ensureList(); 
    expandableListView.setSelectedGroup(groupPosition);
  } 
 
  @Override 
  public void collapseGroup(int groupPosition) {
    ensureList(); 
    expandableListView.collapseGroup(groupPosition);
  } 
 
  abstract public void showDetails(int group, int index);
}