Skip to content

fraggjkee/databinding-recycler-adapter

Repository files navigation

DataBindingRecyclerAdapter

A simple universal RecyclerView.Adapter based on Android's DataBinding. Created to support the following series on Medium:

Installation

Step 0. Make sure that your project is DataBinding-ready. Double check that kotlin-kapt plugin is applied to the target module.

Step 1. Add the JitPack repository to your build file. Add it in your root build.gradle at the end of repositories:

allprojects {
    repositories {
	...
	maven { url 'https://jitpack.io' }
    }
}

Step 2. Add the dependency

dependencies {
    implementation "com.github.fraggjkee:databinding-recycler-adapter:0.2"
}

Sample project structure

/sample folder contains the following examples:

  • Simple: a minimal functional implementation of a static list. Single view type is shared across all items.
  • Simple (Multi Type): similar to Simple sample but additionally demonstrates how to use different view types within a single RecyclerView.
  • Dynamic List: a more advanced implementation demonstrating how to update the adapter's content (add, remove & reorder operations). Additionally provides a primitive implementation of click handling.
  • Dynamic Items: Demonstrates how to update individual items without touching the adapter and it's underlying dataset. Additionally provides a primitive implementation of click handling.
  • Advanced: TODO

FAQ

Q: What about click handlig? How can I implement it without direct access to ViewHolders?
A: Refer to the Dynamic List and Dynamic Items samples.

Q: How do I add, remove or reorder elements?
A: Refer to the Dynamic List sample.

Q: How do I update content within individual cells without updating the entire adapter's dataset?
A: Refer to the Dynamic Items sample.

License

Apache 2.0