@Override
  public View getView(int position, View convertView, ViewGroup parent) {

    IndexPath path = indexPathForPosition(position);

    if (path.row == -1) {
      return delegate.viewForHeaderInSection(path.section);
    } else {
      return delegate.viewForRowAtIndexPath(path);
    }
  }
  @Override
  public int getCount() {

    int count = 0;
    int sections = delegate.sectionCount();

    for (int i = 0; i < sections; i++) {
      count += delegate.rowsInSection(i);
    }

    return count + sections;
  }
  public IndexPath indexPathForPosition(int position) {
    IndexPath path = new IndexPath();

    for (int i = 0; i < delegate.sectionCount(); i++) {
      int rows = delegate.rowsInSection(i);

      if (position - rows - 1 >= 0) {
        position -= (rows + 1);
      } else {
        path.section = i;
        path.row = position - 1;
        return path;
      }
    }

    return path;
  }
        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {

          IndexPath path = SectionListAdapter.this.indexPathForPosition(position);

          if (path.row >= 0) {
            delegate.itemSelectedAtIndexPath(path);
          }
        }