Skip to content
This repository has been archived by the owner on Apr 23, 2019. It is now read-only.

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

Open
adrien-aubel opened this issue Dec 19, 2015 · 7 comments
Open

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

adrien-aubel opened this issue Dec 19, 2015 · 7 comments

Comments

@adrien-aubel
Copy link

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
Copy link
Owner

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
Copy link

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

@truizlop
Copy link
Owner

You could just set its visibility to GONE

@deepakunnikrishnan
Copy link

@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
Copy link
Owner

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
Copy link

@truizlop Thankyou so much.That worked

@hleinone
Copy link

@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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants