Letting the user display, scroll, and manipulate a list of similar data items is a common app feature. Examples of scrollable lists include contact lists, playlists, photo directories, dictionaries and shopping lists, as well as news- and email feeds as shown in the images below.

Previously, you have used ScrollView to scroll a View or ViewGroup. ScrollView is easy to use, but it's not recommended for long, scrollable lists. RecyclerView is a subclass of ViewGroup and is a more resource-efficient way to display scrollable lists. Instead of creating a View for each item that may or may not be visible on the screen, RecyclerView creates a limited number of list items and reuses them for visible content, as shown in the gif below.

What you'll learn

Completing the first 6 exercises will leave you with a working list that utilizes view recycling. To get started, include RecyclerView in your dependencies and layout.

Decide what kind of items you want to display in the list and create the layout for a single item in your RecyclerView.

Create a Plain Old Java Object to hold the data of a single item in the list.

public class Pokemon {
   private String mName;
   private int mIconId;

   Pokemon(String name, int iconId) {
       mName = name;
       mIconId = iconId;
   }

   public String getName() {
       return mName;
   }

   public int getIconId() {
       return mIconId;
   }
}

Set up your Activity to use the RecyclerView and a custom adapter class.

Create the custom adapter class with a constructor, a ViewHolder and the proper methods.

Supply your adapter with data. Everything should be working now - run your application and enjoy! :)

Make the items in the RecyclerView clickable. Whenever the user clicks an item, a Toast with its index number should appear.

Create a list of celebrities containing an image and a name for each celebrity. Male entries should have blue background color and female entries should have a pink background color. When you click on a celebrity a quote from that person should appear in a toast.

The Android framework includes other Views that utilizes adapters. One common example is a Spinner. Try to figure out how to populate a Spinner with data on your own. Make it react to user input.

Change the appearance and behavior of your RecyclerView by utilizing different Layout Managers - e.g. a GridLayoutManager. Also, try to play around with various item animations.