Skip to content
This repository has been archived by the owner on Mar 24, 2023. It is now read-only.

Headers not updating when calling notifyDataSetChanged on adapter #30

Closed
meilers opened this issue Mar 6, 2015 · 14 comments
Closed

Headers not updating when calling notifyDataSetChanged on adapter #30

meilers opened this issue Mar 6, 2015 · 14 comments

Comments

@meilers
Copy link

meilers commented Mar 6, 2015

I use a cursorloader that updates the adapter data set by calling notifyDataSetChanged. All the cells that aren't sticky get updated, but not the sticky headers. In fact, onBindHeaderViewHolder doesn't get called at all.

@jacobtabak
Copy link
Contributor

Thanks for the report, should be a quick fix. We'll look into it right away.
On Mar 5, 2015 10:35 PM, "meilers" notifications@github.com wrote:

I use a cursorloader that updates the adapter data set by calling
notifyDataSetChanged. All the cells that aren't sticky get updated, but not
the sticky headers. In fact, onBindHeaderViewHolder doesn't get called at
all.


Reply to this email directly or view it on GitHub
#30.

@ghost
Copy link

ghost commented Mar 18, 2015

My headers appear but without text, background only. Can be the same issue?

@jacobtabak
Copy link
Contributor

jacobtabak commented Mar 18, 2015 via email

@ghost
Copy link

ghost commented Mar 18, 2015

Yes, you are right. The problem was the text view style.

I added a new issue:
android:singleLine=true on xml makes header text do not appear #33

@meilers
Copy link
Author

meilers commented Mar 30, 2015

Any follow up on this?

@jacobtabak
Copy link
Contributor

Sorry for the delay. You can call decoration.invalidateHeaders() and recyclerView.invalidate() for now. I'll try to add proper support for invalidating the dataset today.

@jacobtabak
Copy link
Contributor

@meilers The decoration isn't directly aware of the RecyclerView's adapter so there's no way to do this automatically. I recommend you add this code when creating your RecyclerView.Adapter:

    adapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
      @Override public void onChanged() {
        super.onChanged();
        decoration.invalidateHeaders();
      }
    });

@meilers
Copy link
Author

meilers commented Apr 3, 2015

Awesome Jacob. Thanks!

@Gruneau
Copy link

Gruneau commented Apr 20, 2015

@jacobtabak I've encountered a similar problem when using the sticky headers. I update the list by swapping out the cursor and calling notifydatasetchanged(). When one extra item is added to the top of the list the entire list expands downwards but the headers remain static (thus in the wrong position by one step). Any ideas?

I've tried invalidating the headers but it does not seem to solve the issue.

@jacobtabak
Copy link
Contributor

Nothing sticks out - but if you can post a sample app to github that reproduce the issue I can take a look.

@Gruneau
Copy link

Gruneau commented Apr 22, 2015

@jacobtabak I found the fix, apparently I had to:

  1. remove the current decoration on the list
  2. create a new instance of the adapter
  3. assign the new adapter to the recyclerview
  4. add a new instance of the header decoration to the recyclerview

like this:

    mRecyclerView.removeItemDecoration(mDecoration);
    mAdapter = getAdapter();
    mAdapter.swapCursor(data);
    mRecyclerView.setAdapter(mAdapter);
    mDecoration = new StickyRecyclerHeadersDecoration(mAdapter);
    mRecyclerView.addItemDecoration(mDecoration);

@jacobtabak
Copy link
Contributor

This really shouldn't be necessary.

@venkataramanaj
Copy link

in sticky header i have check box, when check box checked notify the recyclerview, but not getting refreshed, after scroll, then it is getting refershed. so how to refresh the recyclerview with out scroll

@jacobtabak
Copy link
Contributor

Since the headers are just decorations they are not interactive. So check
boxes won't work. Sorry!

On Fri, Mar 4, 2016, 10:52 PM venkataramanaj notifications@github.com
wrote:

in sticky header i have check box, when check box checked notify the
recyclerview, but not getting refreshed, after scroll, then it is getting
refershed


Reply to this email directly or view it on GitHub
#30 (comment)
.

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