Buggy code:
public class HeaderFooterGridView extends GridView { private static final String TAG = "HeaderFooterGridView" ; private static class FixedViewInfo { public View view ; public ViewGroup viewContainer ; public Object data ; public boolean isSelectable ; } private ArrayList < HeaderFooterGridView . FixedViewInfo > mHeaderViewInfos = new ArrayList < HeaderFooterGridView . FixedViewInfo > ( ) ; private ArrayList < HeaderFooterGridView . FixedViewInfo > mFooterViewInfos = new ArrayList < HeaderFooterGridView . FixedViewInfo > ( ) ; private int mRequestedNumColumns ; private int mNumColmuns = 1 ; private void initHeaderGridView ( ) { } public HeaderFooterGridView ( Context context ) { } public HeaderFooterGridView ( Context context , AttributeSet attrs ) { } public HeaderFooterGridView ( Context context , AttributeSet attrs , int defStyle ) { } @ Override protected void onMeasure ( int widthMeasureSpec , int heightMeasureSpec ) { } @ Override public void setClipChildren ( boolean clipChildren ) { } public void addHeaderView ( View v , Object data , boolean isSelectable ) { } public void addHeaderView ( View v ) { } public void addFooterView ( View v , Object data , boolean isSelectable ) { } public void addFooterView ( View v ) { } public int getHeaderViewCount ( ) { } public int getFooterViewCount ( ) { } public boolean removeHeaderView ( View v ) { } public boolean removeFooterView ( View v ) { } private void removeFixedViewInfo ( View v , ArrayList < HeaderFooterGridView . FixedViewInfo > where ) { } @ Override public void setAdapter ( ListAdapter adapter ) { } private class FullWidthFixedViewLayout extends FrameLayout { public FullWidthFixedViewLayout ( Context context ) { } @ Override protected void onMeasure ( int widthMeasureSpec , int heightMeasureSpec ) { } } @ Override public void setNumColumns ( int numColumns ) { } @ Override public int getNumColumns ( ) { } private static class HeaderFooterViewGridAdapter implements Filterable , WrapperListAdapter { private final DataSetObservable mDataSetObservable = new DataSetObservable ( ) ; private final ListAdapter mAdapter ; private int mNumColumns = 1 ; ArrayList < HeaderFooterGridView . FixedViewInfo > mHeaderViewInfos ; ArrayList < HeaderFooterGridView . FixedViewInfo > mFooterViewInfos ; boolean mAreAllFixedViewsSelectable ; private final boolean mIsFilterable ; public HeaderFooterViewGridAdapter ( ArrayList < HeaderFooterGridView . FixedViewInfo > headerViewInfos , ArrayList < HeaderFooterGridView . FixedViewInfo > footerViewInfos , ListAdapter adapter ) { } public int getHeadersCount ( ) { } public int getFootersCount ( ) { } @ Override public boolean isEmpty ( ) { } public void setNumColumns ( int numColumns ) { } private boolean areAllListInfosSelectable ( ArrayList < HeaderFooterGridView . FixedViewInfo > infos ) { } public boolean removeHeader ( View v ) { } public boolean removeFooter ( View v ) { } @ Override public int getCount ( ) { } @ Override public boolean areAllItemsEnabled ( ) { } @ Override public boolean isEnabled ( int position ) { } @ Override public Object getItem ( int position ) { } @ Override public long getItemId ( int position ) { } @ Override public boolean hasStableIds ( ) { } @ Override public View getView ( int position , View convertView , ViewGroup parent ) { } @ Override public int getItemViewType ( int position ) { int numHeadersAndPlaceholders = ( getHeadersCount ( ) ) * ( mNumColumns ) ; if ( ( position < numHeadersAndPlaceholders ) && ( ( position % ( mNumColumns ) ) != 0 ) ) { return ( mAdapter ) != null ? mAdapter . getViewTypeCount ( ) : 1 ; } if ( ( ( ( mAdapter ) != null ) && ( position >= numHeadersAndPlaceholders ) ) && ( position < ( ( numHeadersAndPlaceholders + ( mAdapter . getCount ( ) ) ) + ( ( mNumColumns ) - ( ( mAdapter . getCount ( ) ) % ( mNumColumns ) ) ) ) ) ) { int adjPosition = position - numHeadersAndPlaceholders ; int adapterCount = mAdapter . getCount ( ) ; if ( adjPosition < adapterCount ) { return mAdapter . getItemViewType ( adjPosition ) ; } else <START_BUG> if ( adapterCount != 0 ) { <END_BUG> return mAdapter . getItemViewType ( ( adapterCount - 1 ) ) ; } } int numFootersAndPlaceholders = ( getFootersCount ( ) ) * ( mNumColumns ) ; if ( ( ( mAdapter ) != null ) && ( position < ( ( numHeadersAndPlaceholders + ( mAdapter . getCount ( ) ) ) + numFootersAndPlaceholders ) ) ) { return ( mAdapter ) != null ? mAdapter . getViewTypeCount ( ) : 1 ; } return AdapterView . ITEM_VIEW_TYPE_HEADER_OR_FOOTER ; } @ Override public int getViewTypeCount ( ) { } @ Override public void registerDataSetObserver ( DataSetObserver observer ) { } @ Override public void unregisterDataSetObserver ( DataSetObserver observer ) { } @ Override public Filter getFilter ( ) { } @ Override public ListAdapter getWrappedAdapter ( ) { } public void notifyDataSetChanged ( ) { } } }

Fix:
if ( ( adapterCount != 0 ) && ( ( mNumColumns ) != 1 ) ) {