Writing List Views for lazy android developers

Ahmed Nabil
2 min readMar 28, 2021
Photo by Sharon Co Images on Unsplash

As an android developer, It’s common to deal with list views and Recycler View, And you, as me, may feel the pain of creating adapters, overriding getItemCount(), onBindViewHolder(), onCreateViewHolder().

Let’s go through the process of creating a simple recycler view and compare it with Jetpack Compose

Here is a simple recycler view adapter, with nested view holder

Sample Adapter class from d.android.com/guide/topics/ui/layout/recyclerview

We are not done yet, you need to add a recycler view to your xml layout, call it from your Kotlin or Java activity or fragment. then set a recycler adapter, layout manager and all that staff, maybe you will need extra code also to show/hide the adapter according to the availability of the items.

setting the adapter to the recycler view, https://gist.github.com/AhmedNMahran/706d94e7a7f5cbc7ecb12b3cfb22322e

For me, I’m too lazy to write all the above code to just create a “simple” recycler view with a text item, this code may have more added lines if we decided to create more complex list items.

So, What is the solution?

Fortunately, Jetpack Compose is here with lazy developers in mind 😀

all the above code can be written as follows:

Simple List with Jetpack Compose, https://gist.github.com/AhmedNMahran/1eab504dfc99b7c50b397e3b49ec916a

That’s it!, With Jetpack Compose, we don’t need xml layouts, nor adapters, all we need is Composable functions, and we are good to go.

As per official android developers website:

Jetpack Compose is Android’s modern toolkit for building native UI. It simplifies and accelerates UI development on Android. Quickly bring your app to life with less code, powerful tools, and intuitive Kotlin APIs.

Note: Jetpack Compose is currently in beta. The 1.0 API surface is feature-complete but may contain bugs. See the release notes for the latest updates.

That’s it for today’s article, follow me for upcoming articles about Jetpack Compose.



Ahmed Nabil

#Kotlin Lover, Android Engineer, Public speaker, Founder of @KotlinEgypt https://linktr.ee/AhmedNMahran