Writing List Views for lazy android developers

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

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.

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:

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.

Kotlin Lover, Android Engineer, Public speaker, twitter.com/AhmedNMahran, youtube.com/AhmedNMahran Founder of Kotlin Egypt : twitter.com/KotlinEgypt