Reputation: 747
I am using https://github.com/emilsjolander/StickyListHeaders as my primary listview for most of my app. I have put this listview in my one layout that I use for all my listviews. However, There are some instances when I don't want to show any headers, I just want to show a regular list, like a listview.
Is there a way to set StickyListHeaders to not show headers at all? There are options for making headers not sticky. I want the headers to just not show up, is that possible with the existing API?
@Override
public View getHeaderView(int position, View convertView, ViewGroup parent) {
// do nothing
return null;
}
@Override
public long getHeaderId(int position) {
// do nothing
return 0;
}
Upvotes: 4
Views: 2394
Reputation: 51
Actually there's a lot simpler way
@Override
public View getHeaderView(int position, View convertView, ViewGroup parent) {
return new View(parent.getContext());
}
Upvotes: 5
Reputation: 462
I also had this requirement recently and ended up patching version 2.3.0 of the library to allow null headers: https://github.com/xlsior/StickyListHeaders/tree/null-headers
Upvotes: 0
Reputation: 1481
I had the same requirement, and succeeded in patching StickyListHeaders to behave like a normal listview when getHeaderView returns null. Untill now, I have not yet run into side effects of this change: https://github.com/mtotschnig/StickyListHeaders/commit/9252a6fe5367bc2421739bb5d34856343236dd24
Upvotes: 2
Reputation:
Try this out to disable sticky list view header:
@Override
public View getHeaderView(int position, View convertView, ViewGroup parent) {
HeaderViewHolder holder;
holder = new HeaderViewHolder();
convertView = inflater.inflate(R.layout.header, parent, false);
holder.text1 = (TextView) convertView.findViewById(R.id.text1);
convertView.setTag(holder);
convertView.setVisibility(View.VISIBLE);
String headerText = "";
} else if (position > mainList.size() - 1) {
headerText = "Categories";
} else {
headerText = "";
return new View(getActivity());
}
holder.text1.setText(headerText);
return convertView;
}
Upvotes: 1