bgogetap / StickyHeaders

Easily add Sticky Headers to your RecyclerView
Apache License 2.0
521 stars 88 forks source link

Header remains after using notifyDataSetChanged() #37

Closed fabiogrum closed 7 years ago

fabiogrum commented 7 years ago

Hi, I have a search feature and a filter feature in my list. I replace the items in my list and I call notifyDataSetChanged() when I use these features. I don't replace the adapter. The problem is when I scroll down the list and there is a header that is almost not visible, it remains visible when I call notifyDataSetChanged(), even if it shouldn't be because the list doesn't contain anymore this header.

bgogetap commented 7 years ago

I tried to reproduce this and am unable to. After a call to notifyDataSetChanged, any stickied header is removed and the correct one is stickied in place (if the list is at the appropriate spot for the new header to be stickied).

If you can reproduce in a sample project I'd gladly take a look.

fabiogrum commented 7 years ago

Hi, thank you for your help. I used your demo : https://github.com/fabiogrum/StickyHeaders.git I added a floating button, who replaces the items of the adapter with an header and an item and calls notifyDataSetChanged().

screenshot_20170424-144324

In this screenshot, you can see that the older header is still there and it hides the new header. I have this problem only if I scroll down the list and there is an header that is almost not visible.

bgogetap commented 7 years ago

Perfect, thanks! I'll take a look in the next few days.

bgogetap commented 7 years ago

I believe this takes care of it. Released in version 0.4.4.

Please let me know if it doesn't solve your issue!

ThanosFisherman commented 7 years ago

Hi, seems like this issue is still here. I'm using DiffUtil to update my items list in recyclerView but notifyDataSetChanged() also triggers this bug.

If I remove the first header from my list along with the items that belong to first header and then update the adapter, the items are gone but the sticky header is still there even though it shouldn't be. Plus the second header (not currently sticky one) dissapears.

Not sure if you understand but let me know if you want me to post a sample or something.

m4limo commented 7 years ago

Still a mystery but I stumbled across the same behaviour even with 0.4.4. Setting the adapter before setting the StickyLayoutManager fixed it somehow.

Before:

StickyLayoutManager layoutManager = new StickyLayoutManager(recyclerView.getContext(), adapter);
layoutManager.elevateHeaders(true);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setAdapter(adapter);

After:

StickyLayoutManager layoutManager = new StickyLayoutManager(recyclerView.getContext(), adapter);
layoutManager.elevateHeaders(true);
recyclerView.setAdapter(adapter);
recyclerView.setLayoutManager(layoutManager);
ThanosFisherman commented 7 years ago

@m4limo Sadly This does not work with DiffUtil but seems to work with notifyDataSetChanged() Very weird

bgogetap commented 7 years ago

@ThanosFisherman I'd definitely be able to have a quicker turnaround on a fix if you had a sample.

But I will look into it on my own either way in the next few days.

ThanosFisherman commented 7 years ago

@bgogetap Ok I modified your sample app a little bit to match my project's setup. Have a look https://github.com/ThanosFisherman/StickyHeaders

I've also came across a new issue that it may or may not be related to this one.

Steps to reproduce new issue:

Steps to reproduce my issue described in this thread:

If you however scroll down until the next non sticky header pushes the already stickied one and then scroll up again the wrong sticky header updates itself with the correct text.

ppamorim commented 7 years ago

@m4limo I had problems with the copy header not being updated, after your solution the problem is gone. Thank you.