diff --git a/library/src/se/emilsjolander/stickylistheaders/AdapterWrapper.java b/library/src/se/emilsjolander/stickylistheaders/AdapterWrapper.java index f86364e5..0fb989e1 100644 --- a/library/src/se/emilsjolander/stickylistheaders/AdapterWrapper.java +++ b/library/src/se/emilsjolander/stickylistheaders/AdapterWrapper.java @@ -163,18 +163,21 @@ public WrapperView getView(int position, View convertView, ViewGroup parent) { WrapperView wv = (convertView == null) ? new WrapperView(mContext) : (WrapperView) convertView; View item = mDelegate.getView(position, wv.mItem, parent); View header = null; - if (previousPositionHasSameHeader(position)) { - recycleHeaderIfExists(wv); - } else { - header = configureHeader(wv, position); - } - if((item instanceof Checkable) && !(wv instanceof CheckableWrapperView)) { - // Need to create Checkable subclass of WrapperView for ListView to work correctly - wv = new CheckableWrapperView(mContext); - } else if(!(item instanceof Checkable) && (wv instanceof CheckableWrapperView)) { - wv = new WrapperView(mContext); + if (mDelegate.shouldShowHeaders()) { + if (previousPositionHasSameHeader(position)) { + recycleHeaderIfExists(wv); + } else { + header = configureHeader(wv, position); + } + if((item instanceof Checkable) && !(wv instanceof CheckableWrapperView)) { + // Need to create Checkable subclass of WrapperView for ListView to work correctly + wv = new CheckableWrapperView(mContext); + } else if(!(item instanceof Checkable) && (wv instanceof CheckableWrapperView)) { + wv = new WrapperView(mContext); + } } wv.update(item, header, mDivider, mDividerHeight); + return wv; } @@ -222,4 +225,9 @@ public long getHeaderId(int position) { return mDelegate.getHeaderId(position); } + @Override + public boolean shouldShowHeaders() { + return mDelegate.shouldShowHeaders(); + } + } diff --git a/library/src/se/emilsjolander/stickylistheaders/ExpandableStickyListHeadersAdapter.java b/library/src/se/emilsjolander/stickylistheaders/ExpandableStickyListHeadersAdapter.java index 5c932070..c7ae771f 100644 --- a/library/src/se/emilsjolander/stickylistheaders/ExpandableStickyListHeadersAdapter.java +++ b/library/src/se/emilsjolander/stickylistheaders/ExpandableStickyListHeadersAdapter.java @@ -33,6 +33,11 @@ public long getHeaderId(int position) { return mInnerAdapter.getHeaderId(position); } + @Override + public boolean shouldShowHeaders() { + return mInnerAdapter.shouldShowHeaders(); + } + @Override public boolean areAllItemsEnabled() { return mInnerAdapter.areAllItemsEnabled(); diff --git a/library/src/se/emilsjolander/stickylistheaders/StickyListHeadersAdapter.java b/library/src/se/emilsjolander/stickylistheaders/StickyListHeadersAdapter.java index 8b80b71f..e5a7590b 100644 --- a/library/src/se/emilsjolander/stickylistheaders/StickyListHeadersAdapter.java +++ b/library/src/se/emilsjolander/stickylistheaders/StickyListHeadersAdapter.java @@ -35,4 +35,12 @@ public interface StickyListHeadersAdapter extends ListAdapter { * The id of the header at the specified position. */ long getHeaderId(int position); + + /** + * Check whether or not the adapter should display header views. + * + * @return + * If false, no headers will be displayed. + */ + boolean shouldShowHeaders(); } diff --git a/library/src/se/emilsjolander/stickylistheaders/StickyListHeadersListView.java b/library/src/se/emilsjolander/stickylistheaders/StickyListHeadersListView.java index cd80f136..0e169163 100644 --- a/library/src/se/emilsjolander/stickylistheaders/StickyListHeadersListView.java +++ b/library/src/se/emilsjolander/stickylistheaders/StickyListHeadersListView.java @@ -509,7 +509,10 @@ public void onScroll(AbsListView view, int firstVisibleItem, mOnScrollListenerDelegate.onScroll(view, firstVisibleItem, visibleItemCount, totalItemCount); } - updateOrClearHeader(mList.getFixedFirstVisibleItem()); + + if (mAdapter != null && mAdapter.shouldShowHeaders()) { + updateOrClearHeader(mList.getFixedFirstVisibleItem()); + } } @Override