Codewaves / Sticky-Header-Grid

Sticky header grid layout manager for RecycleView
MIT License
116 stars 35 forks source link

Expand / Collapse sections? #3

Closed StephenMilone closed 7 years ago

StephenMilone commented 7 years ago

Is it possible to expand and collapse sections dynamically? I'd like to add click listeners to the headers that hide/show the items in it, but can't find a solution at the moment. Let me know if you need any more info. thanks!!

Codewaves commented 7 years ago

It is possible, in your adapter create flag array for show/hide state. In getSectionItemCount return 0 if section is hidden. Add click listener to header view in onBindHeaderViewHolder, flip state flags on click and finally reload all items with notifyAllSectionsDataSetChanged.

The only problem with this solution, current scroll position will jump to incorrect position(for example when you collapse section and header is sticky). You must somehow catch those situations and set correct scroll position.

StephenMilone commented 7 years ago

Thanks, I'll test it out today!

StephenMilone commented 7 years ago

Thanks this is working great for me...but instead of using notifyAllSectionsDataSetChanged, i'd prefer to use notifySectionItemRangeRemoved/ notifySectionItemRangeInserted so it uses animation. but it appears notifySectionItemRangeRemoved has private access. Can this be updated?

The scroll position isn't an issue for my project

Codewaves commented 7 years ago

Access level fixed in 0.9.5