• Stars
    star
    170
  • Rank 223,357 (Top 5 %)
  • Language
    Kotlin
  • License
    Apache License 2.0
  • Created almost 9 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Add Header and/or Footer in your RecyclerView in the simplest way possible.

HFRecyclerView

sample

Platform Maven Central API Twitter

This is an Android library allowing to add Header and/or Footer in your RecyclerView in the simplest way possible.

Android app on Google Play

USAGE

To add Header and/or Footer in your RecyclerView you need to add HFRecyclerView library in your project or you can also grab it from Gradle:

implementation 'com.mikhaellopez:hfrecyclerview:1.2.0'

KOTLIN

  1. You need to create a custom RecyclerView.Adapter for your RecyclerView which HFRecyclerView with the object type of your choice (in my example, my object type is MyDataObject). The first param in HFRecyclerView constructor is a flag to determine if you want to add a header, and the last to add a footer.

    class ExampleAdapter : HFRecyclerView<MyDataObject>(true, true) {
        //...
    }
  2. After that, override 3 methods and create 3 class which extend RecyclerView.ViewHolder in order to add the viewHolder for your Item, your Header and your Footer:

    class ExampleAdapter : HFRecyclerView<MyDataObject>(true, true) {
        
        //...
        
        //region Override Get ViewHolder
        override fun getItemView(inflater: LayoutInflater, parent: ViewGroup): RecyclerView.ViewHolder =
                ViewHolder.ItemViewHolder(inflater.inflate(R.layout.item_example, parent, false))
    
        override fun getHeaderView(inflater: LayoutInflater, parent: ViewGroup): RecyclerView.ViewHolder =
                ViewHolder.HeaderViewHolder(inflater.inflate(R.layout.item_header, parent, false))
    
        override fun getFooterView(inflater: LayoutInflater, parent: ViewGroup): RecyclerView.ViewHolder =
                ViewHolder.FooterViewHolder(inflater.inflate(R.layout.item_footer, parent, false))
        //endregion
        
        //region ViewHolder Header and Footer
        sealed class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
    
            class ItemViewHolder(view: View) : ViewHolder(view) {
                fun bind(item: String) {
                    itemView.run { text.text = item }
                }
            }
    
            class HeaderViewHolder(view: View) : ViewHolder(view)
    
            class FooterViewHolder(view: View) : ViewHolder(view)
        }
        //endregion
    }

    ℹī¸ If you doesn't have a footer (same for header) you need to override getFooterView like this:

    override fun getFooterView(inflater: LayoutInflater, parent: ViewGroup): RecyclerView.ViewHolder? = null
  3. You must override onBindViewHolder method to manage your views as you like:

    class ExampleAdapter : HFRecyclerView<MyDataObject>(true, true) {
    
        //...
    
        override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
            when (holder) {
                is ViewHolder.ItemViewHolder -> holder.bind(getItem(position))
                is ViewHolder.HeaderViewHolder -> { }
                is ViewHolder.FooterViewHolder -> { }
            }
        }
        
        //...
    }
  4. Finally, you can used your adapter and set yout data like this:

    val adapter = ExampleAdapter()
    adapter.data = youtDataList
    recyclerview.adapter = adapter

ℹī¸ You can see a full example here : ExampleAdapter and MainActivity

LICENCE

HFRecyclerView by Lopez Mikhael is licensed under a Apache License 2.0.

More Repositories

1

CircularImageView

Create circular ImageView in Android in the simplest way possible
Kotlin
1,949
star
2

CircularProgressBar

Create circular ProgressBar in Android ⭕
Kotlin
1,698
star
3

CircularFillableLoaders

Realize a beautiful circular fillable loaders to be used for splashscreen 🌊
Java
1,222
star
4

BestAndroidGists

Find best Android Gist đŸ”Ĩ
890
star
5

RxAnimation

Simple way to animate your views on Android with Rx 🚀
Kotlin
590
star
6

AndroidWebServer

Android Web Server (NanoHttpd)
Java
433
star
7

CleanRxArchitecture

Clean Rx Kotlin Architecture sample on GitHub Api 🚀
Kotlin
387
star
8

LazyDatePicker

LazyDatePicker an alternative to the native Android Date Picker 📅
Java
372
star
9

RateBottomSheet

To help to promote your android app by prompting users to rate your app in a BottomSheet ⭐ī¸
Kotlin
308
star
10

GradientView

Create gradient view in Android in the simplest way possible 🌈
Kotlin
197
star
11

CircleView

Create circular view in android (change color, border & shadow) âšĢ
Kotlin
165
star
12

Biometric

The easiest way is to use the new version of Biometric under AndroidX 🔒
Kotlin
140
star
13

PokeCardCompose

PokeCard Compose is a demo app 100% write in Compose, Flow and Koin based on MVI Clean Architecture 🐱⚡ī¸
Kotlin
115
star
14

SaveInsta

Example dynamic update of your theme based on a main color
Java
85
star
15

AutoScrollTextView

Sample Android application show how to set auto scroll in text view in android.
Java
51
star
16

FavoriteAndroidLibrary

My Farorite Android Library
49
star
17

MyToast

Custom Toast on Android
Java
39
star
18

DualShot

With DualShot you take two photos with the front and the back camera, and share both of them in a single image.
Java
23
star
19

WebSideMVC

Structure MVC for Web Side in PHP
PHP
1
star