truizlop / SectionedRecyclerView

An adapter to create Android RecyclerViews with sections, providing headers and footers.
806 stars 144 forks source link

Add `hasHeaderInSection(int section)` method in the adapter #7

Open adrien-aubel opened 8 years ago

adrien-aubel commented 8 years ago

Hi there,

It would be awesome if you could add a protected boolean hasHeaderInSection(int section) (default true for convenience and retro-compatibility).

There are 2 small usages of the hasFooterInSection method so this change should be relatively lightweight.

That would help us use your library without tricks with a RecyclerView having app:stackFromEnd set to true (drawing from the bottom to the top).

That would also help some users to use this library for separators, if they want to not show the first header for example.

truizlop commented 8 years ago

Could you please elaborate a little further on why you need this? If you don't want a header for a section, then don't group those things into different sections. For instance, if you want 2 sections with 3 elements each, but don't want header in the second section, then either hide such header or make a single section with 6 elements. The requirement that you are requesting can be implemented with the current state of the library.

deepakunnikrishnan commented 8 years ago

I want to know how you can remove header for the first section.

truizlop commented 8 years ago

You could just set its visibility to GONE

deepakunnikrishnan commented 8 years ago

@truizlop Thanks. got it working. Could you please help me with another. I cannot add different item layouts based on the viewType in the onCreateItemViewHolder. This method will only have one viewType. Is there any way to get a different viewType ?

truizlop commented 8 years ago

You have to override getSectionItemViewType(int section, int position) and return a different integer number for each viewType that you have. Make sure you don't use the same viewTypes the library is using to distinguish between headers and footers (namely -1, -2, -3; thus, using positive ints is safe).

Then, when you implement onCreateItemViewHolder(ViewGroup parent, int viewType) you will receive those viewTypes and you will have to decide which layout to inflate.

deepakunnikrishnan commented 8 years ago

@truizlop Thankyou so much.That worked

hleinone commented 8 years ago

@truizlop Facing the same issue. Even though I'm setting the header's visibility to View.GONE, the item decoration adding vertical spacing is effective. So, instead of header, I get double vertical spacing on top. I think hasHeaderInSection would be clean way to fix this.