Loading...
Home
  • Tech Blogs
  • Videos
  • Conferences
    • Droidcon News
    • Upcoming Conferences
    • Become a Partner
    • Past Events
    • Keep Me Informed
    • Diversity Scholarships
  • Community
    • droidcon Team
    • How to Hold a Droidcon
  • Android Careers
Sign In

Global CSS

 

How to make a RecyclerView in Jetpack Compose

 

 
Ian Alexander
Android Developer at Octopus Energy
Published: December 15, 2020
Tweet
Share
 
 

Written as of alpha08. Compose is evolving rapidly so some syntax may have changed.

If you’ve developed for android you’ve inevitably come acrossRecyclerView, it’s a massive improvement over ListView which came before, but still pretty far from fun. Making a RecyclerView involves a messy pile of boilerplate — often difficult to re-use between screens — and complexity even for basic tasks, like headers, item callbacks, and multiple item types.

How does Jetpack Compose make lists simpler?

 

Creating a list in compose

Creating a list in compose is ridiculously easy. No adapters. No view holders.

 

 

All you need is a defined data structure and composables to build list items. That’s really it. No joke.

 

 

Item click callbacks

Adding events to list items is also really simple with the use of kotlin lambdas.

 

 

Multiple item types

Jetpack Compose is data driven, so to have multiple item types we start with building the data structure —something which becomes common in compose world.

 

 

And when creating the list use a when statement to choose which composable to make depending on the data item.

 

 

With compose we can spend less time wiring the UI together and more time building attractive UI components backed by solid data structures.

 

Abstracting logic

What you might have noticed about the code samples above is that the view is really dumb.

 

 

Compose makes our view layer dumb by default. In old android you had to work to take logic out of the view layer and into the presentation layer — Presenters, ViewModels, etc — in Jetpack Compose you’d have to work to put logic into the view layer. Good architecture becomes the path of least resistance in compose world.

In compose the logic is all in the data structure and how we manipulate the data structure to display in the UI — the view is made of small re-usable components which react to changes in the data structure. This not only lets us move logic into higher levels of our app’s architecture with ease, it actively encourages it.

For lists, it makes our job ridiculously simple. But how does this work in reality? In the next post I’ll take a look at a real life example.

Happy composing!

For full samples see the repo here

 

 

 

Tags: Android, Android App Development, AndroidDev, Jetpack Compose, Programming

 

View original article at: 


 

Originally published: December 08, 2020

Android News
Compose CameraX on Android
Compose CameraX on Android

By Peng Jiang

Android new UI toolkit Jetpack compose is in beta now, which has all the features you need to build production-ready apps. CameraX is another Jetpack support library, which let you control the camera easier. As compose is still under development, lots of the views are still not available the compose way.

By ProAndroidDev -
Android News
Getting… your BottomSheetScaffold working on Jetpack Compose Beta 03
Getting… your BottomSheetScaffold working on Jetpack Compose Beta 03

By Carlos Mota

It’s Monday, no releases this week, and… there’s a new version of Jetpack Compose — beta 03—available. What a perfect time to just increment 02 to 03 and see what’s new. The API is (almost) final so after updating from alpha to beta there weren’t any big changes to do. However, and remember that’s still in development, there’s always something that I need to update. 

By ProAndroidDev -
Android News
Noisy Code With Kotlin Scopes
Noisy Code With Kotlin Scopes

By Chetan Gupta

Scopes make your code more readable? think again... You are going to encounter these scope functions namely let, run, apply, also, within every Kotlin codebase, along with all the mischievous ways developers exploit their usage from the way they were intended for. Let see how popular opinion on those ends up just as a code noise.

By ProAndroidDev -
Android News
Improving Android DataBinding with Bindables library
Improving Android DataBinding with Bindables library

By Jaewoong Eum

DataBinding is one of the most important factors for MVVM architecture. The basic concept of DataBinding is to link the view and view model via observer patterns, properties, event callbacks, etc. Linking and automating communication between the view via the bound properties or something in the view model has a lot of benefits in the MVVM architecture concept.

By ProAndroidDev -
droidcon News

Tech Showcases,

Developer Resources &

Partners

/portal/rest/jcr/repository/collaboration/Groups/spaces/droidcon_hq/Documents/public/home-details/EmployerBrandingHeader
EmployerBrandingHeader
https://jobs.droidcon.com/
/portal/rest/jcr/repository/collaboration/Groups/spaces/droidcon_hq/Documents/public/employerbranding/jobs-droidcon/jobs.droidcon.com
jobs.droidcon.com

Latest Android Jobs

http://www.kotlinweekly.net/
/portal/rest/jcr/repository/collaboration/Groups/spaces/droidcon_hq/Documents/public/employerbranding/kotlin-weekly/Kotlin Weekly
Kotlin Weekly

Your weekly dose of Kotlin

https://proandroiddev.com/
/portal/rest/jcr/repository/collaboration/Groups/spaces/droidcon_hq/Documents/public/employerbranding/pad/ProAndroidDev
ProAndroidDev

Android Tech Blogs, Case Studies and Step-by-Step Coding

/detail?content-id=/repository/collaboration/Groups/spaces/droidcon_hq/Documents/public/employerbranding/Zalando/Zalando
/portal/rest/jcr/repository/collaboration/Groups/spaces/droidcon_hq/Documents/public/employerbranding/Zalando/Zalando
Zalando

Meet one of Berlin's top employers

/detail?content-id=/repository/collaboration/Groups/spaces/droidcon_hq/Documents/public/employerbranding/Academy for App Success/Academy for App Success
/portal/rest/jcr/repository/collaboration/Groups/spaces/droidcon_hq/Documents/public/employerbranding/Academy for App Success/Academy for App Success
Academy for App Success

Google Play resources tailored for the global droidcon community

Follow us

Team droidcon

Get in touch with us

Write us an Email

 

 

Quicklinks

> Code of Conduct

> Terms and Conditions

> How to hold a conference

> FAQs

> Imprint

Droidcon is a registered trademark of Mobile Seasons GmbH Copyright © 2020. All rights reserved.

powered by Breakpoint One