Top Related Projects
An Android Animation library which easily add itemanimator to RecyclerView items.
The bullet proof, fast and easy to use adapter library, which minimizes developing time to a fraction...
"Favor composition over inheritance" for RecyclerView Adapters
Flexible multiple types for Android RecyclerView.
Epoxy is an Android library for building complex screens in a RecyclerView
An Adapter that allows a RecyclerView to be split into Sections with headers and/or footers. Each Section can have its state controlled individually.
Quick Overview
The CymChad/BaseRecyclerViewAdapterHelper is a powerful and flexible Android library that simplifies the implementation of RecyclerView adapters. It provides a comprehensive set of features and utilities to streamline the development of RecyclerView-based user interfaces.
Pros
- Simplified Adapter Implementation: The library abstracts away the boilerplate code required for setting up a RecyclerView adapter, allowing developers to focus on the core functionality of their application.
- Extensive Feature Set: BaseRecyclerViewAdapterHelper offers a wide range of features, including multiple view types, header/footer support, loading more data, and more, reducing the need for custom implementations.
- Efficient Data Manipulation: The library provides efficient methods for adding, removing, and updating data in the adapter, making it easier to manage dynamic content.
- Customization and Extensibility: The library is designed to be highly customizable, allowing developers to extend its functionality to meet their specific requirements.
Cons
- Learning Curve: The library has a relatively steep learning curve, especially for developers who are new to RecyclerView and adapter implementation.
- Dependency on External Libraries: BaseRecyclerViewAdapterHelper relies on several external libraries, which may increase the overall project size and complexity.
- Potential Performance Overhead: The extensive feature set and abstractions provided by the library may introduce some performance overhead, especially for simple use cases.
- Limited Documentation: While the library is well-documented, the documentation could be more comprehensive, particularly for advanced use cases and customization.
Code Examples
Example 1: Setting up a basic RecyclerView adapter
val adapter = BaseQuickAdapter<MyItem, BaseViewHolder>(R.layout.item_layout, data)
adapter.setOnItemClickListener { _, _, position ->
// Handle item click event
}
recyclerView.adapter = adapter
This code sets up a basic RecyclerView adapter using the BaseQuickAdapter
class provided by the library. The adapter is initialized with a layout resource for the item views and a list of data items.
Example 2: Adding a header and footer to the RecyclerView
val headerView = LayoutInflater.from(context).inflate(R.layout.header_layout, recyclerView, false)
val footerView = LayoutInflater.from(context).inflate(R.layout.footer_layout, recyclerView, false)
adapter.addHeaderView(headerView)
adapter.addFooterView(footerView)
This code demonstrates how to add a header and footer to the RecyclerView using the addHeaderView()
and addFooterView()
methods provided by the BaseQuickAdapter
.
Example 3: Updating the adapter's data
// Add a new item to the adapter
adapter.addData(newItem)
// Remove an item from the adapter
adapter.remove(position)
// Update an item in the adapter
adapter.setData(position, updatedItem)
These examples show how to add, remove, and update data items in the BaseQuickAdapter
using the provided methods.
Getting Started
To get started with the CymChad/BaseRecyclerViewAdapterHelper library, follow these steps:
- Add the library dependency to your project's
build.gradle
file:
dependencies {
implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:3.0.4'
}
- Create a new adapter class that extends
BaseQuickAdapter
:
class MyAdapter : BaseQuickAdapter<MyItem, BaseViewHolder>(R.layout.item_layout) {
override fun convert(holder: BaseViewHolder, item: MyItem) {
// Bind the data to the view holder
holder.setText(R.id.textView, item.text)
}
}
- Set up the RecyclerView and attach the adapter:
val recyclerView = findViewById<RecyclerView>(R.id.recyclerView)
recyclerView.layoutManager = LinearLayoutManager(this)
val adapter = MyAdapter()
adapter.setList(myDataList)
recyclerView.adapter = adapter
- Customize the adapter and add additional
Competitor Comparisons
An Android Animation library which easily add itemanimator to RecyclerView items.
Pros of recyclerview-animators
- Focuses specifically on animations, providing a wide range of pre-built animation options
- Lightweight and easy to implement for basic animation needs
- Allows for custom animations to be created and applied easily
Cons of recyclerview-animators
- Limited functionality beyond animations compared to BaseRecyclerViewAdapterHelper
- Lacks features like item click listeners, drag-and-drop, or swipe-to-delete
- May require additional libraries or code for more complex RecyclerView implementations
Code Comparison
BaseRecyclerViewAdapterHelper:
class MyAdapter : BaseQuickAdapter<String, BaseViewHolder>(R.layout.item_layout) {
override fun convert(holder: BaseViewHolder, item: String) {
holder.setText(R.id.textView, item)
}
}
recyclerview-animators:
val animator = SlideInLeftAnimator()
recyclerView.itemAnimator = animator
The BaseRecyclerViewAdapterHelper example shows how to create a basic adapter with minimal code, while the recyclerview-animators example demonstrates how to apply a pre-built animation to a RecyclerView. BaseRecyclerViewAdapterHelper provides a more comprehensive solution for RecyclerView implementation, while recyclerview-animators excels in providing easy-to-use animations for RecyclerViews.
The bullet proof, fast and easy to use adapter library, which minimizes developing time to a fraction...
Pros of FastAdapter
- More modular and flexible architecture, allowing easier customization
- Better support for multiple view types and complex layouts
- Extensive documentation and samples provided
Cons of FastAdapter
- Steeper learning curve due to its more complex API
- Slightly larger library size compared to BaseRecyclerViewAdapterHelper
- May be overkill for simple list implementations
Code Comparison
FastAdapter:
val fastAdapter = FastAdapter.with(itemAdapter)
recyclerView.adapter = fastAdapter
itemAdapter.add(SimpleItem("Item 1"))
itemAdapter.add(SimpleItem("Item 2"))
BaseRecyclerViewAdapterHelper:
val adapter = MyAdapter()
recyclerView.adapter = adapter
adapter.setNewData(listOf("Item 1", "Item 2"))
FastAdapter offers a more modular approach, separating the adapter and item management, while BaseRecyclerViewAdapterHelper provides a simpler, more straightforward implementation. FastAdapter's architecture allows for easier handling of multiple view types and complex layouts, but it comes at the cost of a steeper learning curve and slightly more verbose code. BaseRecyclerViewAdapterHelper is more suitable for simpler list implementations, offering a more concise API but with less flexibility for complex scenarios.
"Favor composition over inheritance" for RecyclerView Adapters
Pros of AdapterDelegates
- Promotes a more modular and flexible approach to adapter design
- Easier to maintain and extend for complex list structures
- Better separation of concerns for different view types
Cons of AdapterDelegates
- Slightly more complex setup compared to BaseRecyclerViewAdapterHelper
- May require more initial code for simple use cases
- Less built-in functionality for common RecyclerView operations
Code Comparison
AdapterDelegates:
class CatAdapterDelegate : AdapterDelegate<List<Animal>>() {
override fun isForViewType(items: List<Animal>, position: Int): Boolean {
return items[position] is Cat
}
// ... other methods
}
BaseRecyclerViewAdapterHelper:
class AnimalAdapter : BaseQuickAdapter<Animal, BaseViewHolder>(R.layout.item_animal) {
override fun convert(holder: BaseViewHolder, item: Animal) {
// Handle all animal types in one place
}
}
AdapterDelegates focuses on separating different view types into distinct classes, promoting modularity. BaseRecyclerViewAdapterHelper provides a more straightforward approach with built-in functionality for common RecyclerView operations. The choice between the two depends on the complexity of your list and your preference for code organization.
Flexible multiple types for Android RecyclerView.
Pros of MultiType
- Simpler and more lightweight, focusing on multi-type list views
- More flexible type system, allowing for easier customization
- Better support for Kotlin and coroutines
Cons of MultiType
- Less comprehensive feature set compared to BaseRecyclerViewAdapterHelper
- Smaller community and fewer resources available
- May require more manual implementation for advanced features
Code Comparison
MultiType:
class TextItemViewBinder : ItemViewBinder<TextItem, TextItemViewBinder.ViewHolder>() {
override fun onCreateViewHolder(inflater: LayoutInflater, parent: ViewGroup): ViewHolder {
return ViewHolder(inflater.inflate(R.layout.item_text, parent, false))
}
override fun onBindViewHolder(holder: ViewHolder, item: TextItem) {
holder.text.text = item.text
}
class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
val text: TextView = itemView.findViewById(R.id.text)
}
}
BaseRecyclerViewAdapterHelper:
class TextAdapter : BaseQuickAdapter<TextItem, BaseViewHolder>(R.layout.item_text) {
override fun convert(holder: BaseViewHolder, item: TextItem) {
holder.setText(R.id.text, item.text)
}
}
Both libraries aim to simplify RecyclerView adapter implementation, but MultiType focuses on multi-type lists with a more flexible type system, while BaseRecyclerViewAdapterHelper provides a broader set of features and utilities for various adapter scenarios.
Epoxy is an Android library for building complex screens in a RecyclerView
Pros of Epoxy
- More powerful and flexible for complex RecyclerView layouts
- Built-in support for data binding and view binding
- Better performance for large lists with automatic diffing
Cons of Epoxy
- Steeper learning curve and more complex setup
- Requires more boilerplate code for simple use cases
- Larger library size and potential impact on app size
Code Comparison
BaseRecyclerViewAdapterHelper:
class MyAdapter : BaseQuickAdapter<Item, BaseViewHolder>(R.layout.item_layout) {
override fun convert(holder: BaseViewHolder, item: Item) {
holder.setText(R.id.title, item.title)
}
}
Epoxy:
@EpoxyModelClass(layout = R.layout.item_layout)
abstract class ItemModel : EpoxyModelWithHolder<ItemHolder>() {
@EpoxyAttribute lateinit var title: String
override fun bind(holder: ItemHolder) {
holder.titleView.text = title
}
}
BaseRecyclerViewAdapterHelper is simpler and more straightforward for basic use cases, while Epoxy provides more power and flexibility for complex layouts at the cost of increased complexity. Epoxy shines in scenarios with diverse view types and dynamic content, while BaseRecyclerViewAdapterHelper is often sufficient for simpler list implementations.
An Adapter that allows a RecyclerView to be split into Sections with headers and/or footers. Each Section can have its state controlled individually.
Pros of SectionedRecyclerViewAdapter
- Specialized for creating sectioned RecyclerViews with headers and footers
- Simpler API for handling sections, reducing boilerplate code
- Built-in support for expandable sections
Cons of SectionedRecyclerViewAdapter
- Less feature-rich compared to BaseRecyclerViewAdapterHelper
- Limited to sectioned layouts, less flexible for other RecyclerView use cases
- Smaller community and fewer updates
Code Comparison
SectionedRecyclerViewAdapter:
Section section = new Section(headerResourceId, itemResourceId) {
@Override
public int getContentItemsTotal() {
return items.size();
}
@Override
public RecyclerView.ViewHolder getItemViewHolder(View view) {
return new ItemViewHolder(view);
}
};
BaseRecyclerViewAdapterHelper:
public class MyAdapter extends BaseQuickAdapter<MyItem, BaseViewHolder> {
public MyAdapter(int layoutResId, List<MyItem> data) {
super(layoutResId, data);
}
@Override
protected void convert(BaseViewHolder helper, MyItem item) {
helper.setText(R.id.tv_title, item.getTitle());
}
}
SectionedRecyclerViewAdapter focuses on creating sectioned layouts with a dedicated API, while BaseRecyclerViewAdapterHelper provides a more general-purpose solution with additional features for RecyclerView adapters. The choice between the two depends on the specific requirements of your project and whether you need specialized sectioned support or a more versatile adapter helper.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
BRVAH
Powerful and flexible RecyclerView Adapter, Please feel free to use this. (Welcome to Star and Fork)
强大èçµæ´»çRecyclerView Adapterï¼æ¬¢è¿ Star å Forkï¼
â
æ°ç4.x.xå·²åå¸ï¼å®ç¾å
¼å®¹ConcatAdapter
ï¼è§£å³äºè®¸å¤éçé®é¢ï¼æåäºåè½æ¨¡åï¼BaseAdapteræ´å ç®æ´å¹²åãâå¤ç±»åå¸å±âæ´å çµæ´»ãåä¸ãåä¸å è½½å¾å°æ大å 强ã
v4çæ¬å·²ç»ä¸ä¼ maven ä¸å¤®ä»åºï¼ä¸éè¦åå¼å
¥ä¸æ¹ä»åºé
ç½®äºã欢è¿å°è¯ã
implementation "io.github.cymchad:BaseRecyclerViewAdapterHelper4:4.1.4"
Of course, you can continue to use the 2.x version.
å½ç¶ï¼ä½ ä¹å¯ä»¥ç»§ç»ä½¿ç¨2.x çæ¬ã3.xçæ¬ã
Document
- English Writing ...
- 3.0çæ¬ ä¸æ
- 4.0çæ¬ ä¸æ
(ç±äºåä½é¡¹ç®æåå·¥ä½è¾ä¸ºç¹å¿ï¼è¯·åä½åå¦è° 解)
v4 çæ¬ Demo
proguard-rules.pro
æ¤èµæºåºèªå¸¦æ··æ·è§åï¼å¹¶ä¸ä¼èªå¨å¯¼å ¥ï¼æ£å¸¸æ åµä¸æ éæå¨å¯¼å ¥ã
The library comes with
proguard-rules.pro
rules and is automatically imported. Normally no manual import is required. You can also go here to view proguard-rules
Thanks
JoanZapata / base-adapter-helper
License
Top Related Projects
An Android Animation library which easily add itemanimator to RecyclerView items.
The bullet proof, fast and easy to use adapter library, which minimizes developing time to a fraction...
"Favor composition over inheritance" for RecyclerView Adapters
Flexible multiple types for Android RecyclerView.
Epoxy is an Android library for building complex screens in a RecyclerView
An Adapter that allows a RecyclerView to be split into Sections with headers and/or footers. Each Section can have its state controlled individually.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot