GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - rubengees/easy-header-footer-adapter: An Android library which adds headers and footers to the RecyclerView.

BranchesTags
Open more actions menu

Latest commit

 

History

45 Commits
45 Commits

Folders and files

NameName
Last commit message
Last commit date
.circleci
.circleci
 
 
.github
.github
 
 
art
art
 
 
easy-header-footer-adapter
easy-header-footer-adapter
 
 
gradle/wrapper
gradle/wrapper
 
 
sample
sample
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
build.gradle
build.gradle
 
 
gradlew
gradlew
 
 
gradlew.bat
gradlew.bat
 
 
jitpack.yml
jitpack.yml
 
 
settings.gradle
settings.gradle
 
 

Repository files navigation

easy-header-footer-adapter Release API CircleCI

Add a header and/or footer to your RecyclerView - the easy way.

Sample

You can download the latest sample app here.

Features

  • Completely hassle-free. You don't have to change your existing implementation.
  • Support for LinearLayoutManager, GridLayoutManager and StaggeredGridLayoutManager.
  • LayoutParams of your Views are honoured.
  • The SpanSizeLookup of your GridLayoutManager continues to work without adjustments.
  • Support for stable ids.

Include in your Project

Add this to your root build.gradle (usually in the root of your project):

repositories {
    maven { url "https://jitpack.io" }
}

And this to your module build.gradle (usually in the app directory):

dependencies {
    compile 'com.github.rubengees:easy-header-footer-adapter:3.0.0@aar'
}

If that doesn't work, look if there is a new version and the Readme was not updated yet.

Usage

There is almost zero configuration if you already have an adapter.
You wrap your adapter in the EasyHeaderFooterAdapter and set it to the RecyclerView like this:

YourAdapter adapter = new YourAdapter();
EasyHeaderFooterAdapter easyHeaderFooterAdapter = 
                new EasyHeaderFooterAdapter(adapter);

//Always set the LayoutManager BEFORE the adapter.
recyclerView.setLayoutManager(new SomeLayoutManager());
recyclerView.setAdapter(easyHeaderFooterAdapter);

You can then set a header or footer through the setHeader and setFooter methods:

headerFooterAdapter.setHeader(anyView);
headerFooterAdapter.setFooter(anotherView);

Those can be removed by setting null to the aforementioned methods:

headerFooterAdapter.setHeader(null);
headerFooterAdapter.setFooter(null);

And that's it! Easy right?

There are a view things to look out for though.

Positions

If you are using the positions returned by the ViewHolders getAdapterPosition method, you have to calculate the real position in your adapter. The method getRealPosition does exactly that:

adapter.setCallback(new MainAdapter.MainAdapterCallback() {
    @Override
    public void onItemClick(int position) {
        int positionInYourDataSet = headerFooterAdapter.getRealPosition(position);

        // Do whatever you wanted to do with it.
    }
});

You can find more info on that in the sample.

ViewTypes and Ids

The following ViewTypes and IDs are used internally, so don't use them yourself:

TYPE_HEADER = Integer.MIN_VALUE;
TYPE_FOOTER = Integer.MIN_VALUE + 1;
ID_HEADER = Long.MIN_VALUE;
ID_FOOTER = Long.MIN_VALUE + 1;
Changing the LayoutManager at runtime

As the EasyHeaderFooterAdapter needs to configure your LayoutManager, you have to reset the adapter to the RecyclerView if you want to change the LayoutManager:

recycler.setLayoutManager(new YourNewLayoutManager());

// Remember, always set if after the LayoutManager
recycler.setAdapter(headerFooterAdapter);

Further reading

The sample features almost all use cases. Have a look here.
You can find the JavaDoc here.

Metrics

Contributions and contributors

A guide for contribution can be found here.

About

An Android library which adds headers and footers to the RecyclerView.

Topics

adapterandroidfooterheaderlibraryrecyclerview

Resources

Readme
MIT license

Contributing

Contributing
Activity

Stars

44 stars

Watchers

1 watching

Forks

4 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402894 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.