Chapter 8. Other GUI Elements: Lists and Views

It may seem odd to have a separate chapter for the RecyclerView and ListView components. But these are, in fact, among the most important GUI components, being used in probably 80% of all Android applications. And these list components are very flexible; you can do a lot with them, but figuring out how to do it is sometimes not as intuitive as it could be.

In this chapter we cover topics from basic RecyclerView and ListView uses through to advanced uses.

So why are there two list components? ListView has been around since the beginning of Android time. RecyclerView was introduced around 2015 as a more modern replacement, but many applications still use the original ListView, so we discuss both.

A good overview of ListView can be found in a Google I/O 2010 talk that’s available on Google’s YouTube channel; this was presented by Google employees Romain Guy and Adam Powell, who work on the code for ListView.

8.1 Building List-Based Applications with RecyclerView

Ian Darwin

Problem

RecyclerView is a modern reinterpretation of the classical ListView. You want to learn when and how to use the new paradigm.

Solution

Use a RecyclerView.

Discussion

You could argue that RecyclerView is badly named. It should have been called ListView2 or something similar, to tie it in to the ListView, which it aims to replace. Paraphrasing Dr. Seuss: “But they didn’t, and now it’s too late.” It’s called RecyclerView because it is better at recycling ...

Get Android Cookbook, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.