Closed pipipzz closed 4 years ago
I have an adapter that successfully implements StickyHeaderAdapter
with 6 different view types - some with and some without headers. Are you adding a StickyHeaderDecoration
item decoration to your RecyclerView
?
@starkej2 can you provide for an example it would be very useful
Unfortunately don't have any non-proprietary code I can show right now. I can try to add an example to the sample app, but probably won't have time to do that in the near future.
This library isn't really concerned with how many view types exist, so any problems that occur with that use case are probably caused by an error in the implementation of the StickyHeaderAdapter
.
@starkej2 I have a use case where in i have a list with multiple view types, eg, a contact listing grouped by alphabets, where in each group header would be the Alphabet and the other view types would be the contact them selfs. So what would be the implementation for getHeaderId(int position)
return?
public long getHeaderId(int position) {
if(data.get(position).getViewType == VIEW_HEADER){
return position;
else
return StickyHeaderDecoration.NO_HEADER_ID;
}
Also a side question, does paging if any affect the implementation?
@baradvaibhav1 You can kind of think of it as sections. You don't need to define a header view type in your adapter. Instead each item that should be underneath the same header should return the same header ID.
For example:
item1 - getHeaderId() returns 10001
item2 - getHeaderId() returns 10001
item3 - getHeaderId() returns 10002
item4 - getHeaderId() returns 10002
item5 - getHeaderId() returns 10003
will be rendered like this:
header (10001)
item1
item2
header (10002)
item3
item4
header (10003)
item5
The sample app isn't super thorough, but should help get you started. You probably don't need to use NO_HEADER_ID
since that is designed to be used for items that are not part of a header group.
I implemented my adapter using the library, but still I am not able to make headers stick. Here is my adapter implementation:
I see that the getHeaderId() is never called. I have one type of view which will be header and 3 other view types that would not be header and won't stick. What's wrong with my implementation?