@Override
 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
   super.onMeasure(widthMeasureSpec, heightMeasureSpec);
   ListAdapter adapter = getAdapter();
   if (adapter != null && adapter instanceof HeaderViewGridAdapter) {
     ((HeaderViewGridAdapter) adapter).setNumColumns(getNumColumnsCompatible());
     ((HeaderViewGridAdapter) adapter).setRowHeight(getRowHeight());
   }
 }
 @Override
 public void setAdapter(ListAdapter adapter) {
   mOriginalAdapter = adapter;
   if (mHeaderViewInfos.size() > 0 || mFooterViewInfos.size() > 0) {
     HeaderViewGridAdapter headerViewGridAdapter =
         new HeaderViewGridAdapter(mHeaderViewInfos, mFooterViewInfos, adapter);
     int numColumns = getNumColumnsCompatible();
     if (numColumns > 1) {
       headerViewGridAdapter.setNumColumns(numColumns);
     }
     headerViewGridAdapter.setRowHeight(getRowHeight());
     super.setAdapter(headerViewGridAdapter);
   } else {
     super.setAdapter(adapter);
   }
 }