hide/show or enable/disable headers
There should be a way to hide all headers and a way to show headers. Similar to setting visibility to VISIBLE and GONE.
My Workaround:
@Override
public View getHeaderView(int position, View convertView, ViewGroup parent) {
if (!mShowSections) {
View v = new View(mContext);
v.setVisibility(View.GONE);
return v;
}
...
}
...
@Override
public long getHeaderId(int position) {
if (!mShowSections) {
return 0;
}
return ...;
}
There used to be a pull request which let you easily do this by returning null in the header methods, but it was rejected.
https://github.com/emilsjolander/StickyListHeaders/pull/163 allow to suppress grouping by returning null from getHeaderView
@cmaier your adapter "hack" work, but there is little problem with this solution. The first header will take some space in the StickyListHeadersListView. The first divider will not be draw.
I hope this feature will be implemented.
public interface StickyListHeadersAdapter extends android.widget.ListAdapter { ... public boolean isHeaderShow(boolean isShown); ... }
I encountered this issue as well in many projects actually. For example, we have a TransactionsListFragment which uses a StickyListHeaderListView for grouping multiple transactions under the same day. But in some areas of our app we need the same fragment without the day grouping. So a simple isHeaderShow(boolean) like Neige wrote above would be more than perfect. Hell, even the null hack pull request would still be a great addition rather than nothing. Until this issue is resolved, I have to also use another plain ListView inside the layout in order to achieve this... not cool man.... So, can you guys consider at least merging in the pull request, if not adding the aforementioned method ?
It seems not so safe that returning null in getHeaderView method. May be we have any other way to implement the feature.
There is possibility to hide all headings, for example depending on item count(10) , if you use this logic if(fullList.size()>9){ mListView.setAdapter(adapter); }else{ mListView.getWrappedList().setAdapter(adapter); // This is the main point } But the wrapper method has this description - Use the method with extreme caution!!... With this logic it is easy to control the headings and there are no problems with GONE view that takes space.
So no intention to actually make this baked into the API ? It's been almost 1 and a half years since the initial request...
+1 It'd be super beneficial.