code: public void apply(List items) {
          //If the list is empty avoid sorting and adding headers.
          int size = items.size();
          if (size > 0) {
              //sort beforehand
              if (comparator != null) {
                  Collections.sort(items, comparator);
              }
  
              //we have to get the list size each time, as we will add the headers to it
              for (int i = -1; i < size; i++) {
                  HeaderItem headerItem;
                  if (i == -1) {
                      headerItem = groupingFunction.group(null, (Item) items.get(i + 1), i);
                  } else if (i == size - 1) {
                      headerItem = groupingFunction.group((Item) items.get(i), null, i);
                  } else {
                      headerItem = groupingFunction.group((Item) items.get(i), (Item) items.get(i + 1), i);
                  }
  
                  if (headerItem != null) {
                      items.add(i + 1, headerItem);
                      i = i + 1;
                      size = size + 1;
                  }
              }
          }
  
          /**
           * set the sorted list to the modelAdapter if provided
           */
          if (modelAdapter != null) {
              modelAdapter.set(items);
          }
      }
docs: call this when your list order has changed or was updated, and you have to readd the headres
  
  @param items the list which will get the headers added inbetween