{"id":18663792,"url":"https://github.com/lopspower/hfrecyclerview","last_synced_at":"2025-04-07T19:16:17.842Z","repository":{"id":57726692,"uuid":"51938970","full_name":"lopspower/HFRecyclerView","owner":"lopspower","description":"Add Header and/or Footer in your RecyclerView in the simplest way possible.","archived":false,"fork":false,"pushed_at":"2021-05-31T16:07:12.000Z","size":2476,"stargazers_count":169,"open_issues_count":1,"forks_count":40,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-03-31T16:21:28.129Z","etag":null,"topics":["java","kotlin","recyclerview","recyclerviewadapter"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lopspower.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-02-17T16:54:18.000Z","updated_at":"2024-12-30T23:07:10.000Z","dependencies_parsed_at":"2022-09-05T20:22:04.169Z","dependency_job_id":null,"html_url":"https://github.com/lopspower/HFRecyclerView","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lopspower%2FHFRecyclerView","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lopspower%2FHFRecyclerView/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lopspower%2FHFRecyclerView/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lopspower%2FHFRecyclerView/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lopspower","download_url":"https://codeload.github.com/lopspower/HFRecyclerView/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247713258,"owners_count":20983683,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["java","kotlin","recyclerview","recyclerviewadapter"],"created_at":"2024-11-07T08:19:48.381Z","updated_at":"2025-04-07T19:16:17.819Z","avatar_url":"https://github.com/lopspower.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"HFRecyclerView\n=================\n\n\u003cimg src=\"/preview/preview.gif\" alt=\"sample\" title=\"sample\" width=\"300\" height=\"435\" align=\"right\" vspace=\"20\" /\u003e\n\n[![Platform](https://img.shields.io/badge/platform-android-green.svg)](http://developer.android.com/index.html)\n[![Maven Central](https://img.shields.io/maven-central/v/com.mikhaellopez/hfrecyclerview.svg?label=Maven%20Central)](https://search.maven.org/artifact/com.mikhaellopez/hfrecyclerview)\n[![API](https://img.shields.io/badge/API-14%2B-brightgreen.svg?style=flat)](https://android-arsenal.com/api?level=14)\n[![Twitter](https://img.shields.io/badge/Twitter-@LopezMikhael-blue.svg?style=flat)](http://twitter.com/lopezmikhael)\n\nThis is an Android library allowing to add **Header** and/or **Footer** in your RecyclerView in the simplest way possible.\n\n\u003ca href=\"https://play.google.com/store/apps/details?id=com.mikhaellopez.lopspower\"\u003e\n  \u003cimg alt=\"Android app on Google Play\" src=\"https://developer.android.com/images/brand/en_app_rgb_wo_45.png\" /\u003e\n\u003c/a\u003e\n\nUSAGE\n-----\n\nTo 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:\n\n```groovy\nimplementation 'com.mikhaellopez:hfrecyclerview:1.2.0'\n```\n\nKOTLIN\n-----\n\n1. 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.\n\n    ```kotlin\n    class ExampleAdapter : HFRecyclerView\u003cMyDataObject\u003e(true, true) {\n        //...\n    }\n    ```\n2. 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:\n\n    ```kotlin\n    class ExampleAdapter : HFRecyclerView\u003cMyDataObject\u003e(true, true) {\n        \n        //...\n        \n        //region Override Get ViewHolder\n        override fun getItemView(inflater: LayoutInflater, parent: ViewGroup): RecyclerView.ViewHolder =\n                ViewHolder.ItemViewHolder(inflater.inflate(R.layout.item_example, parent, false))\n\n        override fun getHeaderView(inflater: LayoutInflater, parent: ViewGroup): RecyclerView.ViewHolder =\n                ViewHolder.HeaderViewHolder(inflater.inflate(R.layout.item_header, parent, false))\n\n        override fun getFooterView(inflater: LayoutInflater, parent: ViewGroup): RecyclerView.ViewHolder =\n                ViewHolder.FooterViewHolder(inflater.inflate(R.layout.item_footer, parent, false))\n        //endregion\n        \n        //region ViewHolder Header and Footer\n        sealed class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {\n\n            class ItemViewHolder(view: View) : ViewHolder(view) {\n                fun bind(item: String) {\n                    itemView.run { text.text = item }\n                }\n            }\n\n            class HeaderViewHolder(view: View) : ViewHolder(view)\n\n            class FooterViewHolder(view: View) : ViewHolder(view)\n        }\n        //endregion\n    }\n    ```\n    \n    :information_source: If you doesn't have a footer (same for header) you need to override `getFooterView` like this:\n\n    ```kotlin\n    override fun getFooterView(inflater: LayoutInflater, parent: ViewGroup): RecyclerView.ViewHolder? = null\n    ```\n\n3. You must override `onBindViewHolder` method to manage your views as you like:\n\n    ```kotlin\n    class ExampleAdapter : HFRecyclerView\u003cMyDataObject\u003e(true, true) {\n    \n        //...\n    \n        override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {\n            when (holder) {\n                is ViewHolder.ItemViewHolder -\u003e holder.bind(getItem(position))\n                is ViewHolder.HeaderViewHolder -\u003e { }\n                is ViewHolder.FooterViewHolder -\u003e { }\n            }\n        }\n        \n        //...\n    }\n    ```\n4. Finally, you can used your adapter and set yout data like this:\n\n    ```kotlin\n    val adapter = ExampleAdapter()\n    adapter.data = youtDataList\n    recyclerview.adapter = adapter\n    ```\n\n:information_source: You can see a full example here : [**ExampleAdapter**](/hfrecyclerview-example/src/main/java/com/mikhaellopez/hfrecyclerviewexample/ExampleAdapter.kt) and [**MainActivity**](/hfrecyclerview-example/src/main/java/com/mikhaellopez/hfrecyclerviewexample/MainActivity.kt)\n\nLICENCE\n-----\n\nHFRecyclerView by [Lopez Mikhael](http://mikhaellopez.com/) is licensed under a [Apache License 2.0](http://www.apache.org/licenses/LICENSE-2.0).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flopspower%2Fhfrecyclerview","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flopspower%2Fhfrecyclerview","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flopspower%2Fhfrecyclerview/lists"}