question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Update view from normal header to sticky header

See original GitHub issue

In my app, the sticky headers have an extra view added to them over the basic header. How can I do this? I tried forking the library and adding the sticky header position to the IFlexible onBindView method: bindViewHolder(FlexibleAdapter adapter, VH holder, int position, int stickyPosition, List payloads)

This way I can update the sticky header, but the changes are not reverted when the sticky header is changed, because the header is not bound again.

Congratulations for the library! It is very powerful, but the FlexibleAdapter class is huge. It’s size should be reduced. Maybe more helper classes like StickyHeaderHelpercould be made.

Any help is welcome, thanks!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:20 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
NegreaVladcommented, Aug 14, 2017

@davideas Thanks for the help, you are 100% right. The alpha animation was caused by the DefaultItemAnimator.

Both of your suggestions fix the issue. I had gone with the first, using notifyItemChanged(mStickyHeaderPosition, payload); to keep the add/remove animations.

The final code:

    @Override
    public void bindViewHolder(FlexibleAdapter adapter, MeetingsHeaderViewHolder holder, int position, List payloads) {
        if (adapter.getStickyPosition() == position) {
            showTodayJump(holder);
        } else {
            hideTodayJump(holder);

            if (payloads.size() == 1 && payloads.get(0) instanceof UpdateHeaderEvent) {
                return;
            }
        }

        holder.mDayTV.setText(mDayNumber);
        holder.mMonthTV.setText(mMonth);

        setupWeekday(holder);
        setupDateColor(holder);
    }
                .addListener(
                        (FlexibleAdapter.OnStickyHeaderChangeListener) index -> {
//                            mHandler.post(() -> {
                                // If there is a previous sticky header or this is the first header that is converted to a
                                // sticky header
                                if (mStickyHeaderPosition != -1 || index == 0) {
                                    Log.d("StickyHeaderButton", "initializeRecyclerView: Notifying sticky position changed: " + mStickyHeaderPosition);
                                    mAdapter.notifyItemChanged(mStickyHeaderPosition, new UpdateHeaderEvent());
                                }

                                mStickyHeaderPosition = index;
//                            });
                        });

UpdateHeaderEvent is an empty POJO.

1reaction
davideascommented, Jun 22, 2017

The second solution, in bindViewHolder you have the position and adapter.getStickyPosition().

Read more comments on GitHub >

github_iconTop Results From Across the Web

Sticky Headers: 5 Ways to Make Them Better
Sticky headers (or persistent headers) are a common pattern for keeping the header of a website or app in the same place on...
Read more >
How to create a sticky website header | Layout - Flywheel
Declare the distance from the “sticky edge,” i.e. 10px for a header that becomes sticky when it is 10px away from scroll area....
Read more >
How To Create the Perfect Sticky Header for Your Site With ...
1. Sticky Menu & Sticky Header. Webfactory's Sticky Menu & Sticky Header plugin is a good first choice, due to its wealth of...
Read more >
Better Headers: How to Configure Sticky Headers - YouTube
Sticky header controls left you scratching your head? ... 2.5K views 2 years ago ... Never miss a life-changing Themeco update again!
Read more >
How to Add a Sticky Header or On-scroll Fixed Header with ...
In the customizer under Header > Sticky Header all options are available. If you have a sticky primary header, respective options will appear....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found