RecyclerView Adapter with Anko

Abduaziz Kayumov
2 min readMay 25, 2018

Anko Layouts has already proved that it can be used anywhere to design Android app layouts without XML. However, it lacks a complete documentation to fully engage with it. I am writing this story to share my experience about the construction of RecyclerView Adapter with Anko.

Let me assume you have created a new project on Android Studio and set up everything ready to work.

Step 1. Add Anko dependencies to your app level gradle file:

implementation "com.android.support:recyclerview-v7:27.1.1"
implementation "org.jetbrains.anko:anko-sdk15:0.10.5"
implementation "org.jetbrains.anko:anko-appcompat-v7:0.10.5"
implementation "org.jetbrains.anko:anko-recyclerview-v7:0.10.5"

Step 2. Create a simple data class in Kotlin, for example:

Step 3. Create a new layout using Anko Layouts DSL:

You may be wondering why view ids are constant and not given at runtime. There are some other blogs that suggest you to give ids using ids.xml:

View IDs need not be unique throughout the view tree, but it is good practice to ensure that they are at least unique within the part of the tree you are searching.

You may use the ids.xml, but my goal was to be independent from any XML and avoid a museum of ids (which will be hard to maintain later).

Step 4. Create a simple recycler view adapter:

Step 5. Finally, create some movie objects and use the adapter:

The result would be similar to this:

Thank you for reading this article. If you find it useful, clap 👏 and help others to find this article.

The full source code is here:

--

--