This is a play ground project of implementing adapter delegate in Android.
![]() |
![]() |
Playground | Playstore |
This project is a playground for anyone who want to try implementing adapter delegate. Adapter delegate is a technique that help us to create a heterogeneous RecyclerView
. Instead of using viewType
and if else
technique in the adapter and ended creating a God Class, we can try implementing delegate
technique in order to provide multiple views in a RecyclerView
.
Favor composition over inheritance
Now look at this code:
class MainAdapter : ListDelegationAdapter<List<DisplayableItem>>(
bannerAdapterDelegate(),
campaignAdapterDelegate(),
featuredAdapterDelegate(),
promotionAdapterDelegate()
)
This is an example when we implementing delegate technique in an adapter. As You can see, we can just add and remove the delegate adapter to add or remove the view as the requirements of our apps. It will make our adapter more clean and maintainable.
code of adapter delegate:
fun bannerAdapterDelegate() = adapterDelegateViewBinding<Banner, DisplayableItem, ItemBannerBinding>(
{ layoutInflater, root -> ItemBannerBinding.inflate(layoutInflater, root, false) }
) {
bind {
// bind your view with your data
}
}
using Adapter Delegate library and ViewBinding
we can create something like that. very clean easy to read.
For now this project implementing Adapter Delegate library. But not close the possibility to use code from scratch.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE
for more information.
Anang Kurniawan - @anang_kur - anang@sampingan.co.id