Display Sample Data when Creating a RecyclerView

When creating a RecyclerView in Android Studio, it can be helpful to add sample data to the RecyclerView to help with debugging. By default, the following is shown in the Preview and Design Layout Editor tab.

A fullscreen RecyclerView

With only a little work, we can convert this RecyclerView to the following. Isn’t that more helpful? Now you can see how the images and text shows up, right in the editor!

The editor with random sample data, provided by Android Studio, using the tools: attribute.

Let’s assume you already have your layout files for the RecyclerView.

With a little modification, we can display an avatar and random last name. We can add one line to each file. First, let’s modify the RecyclerView in the first file, the content_main.xml file, by adding the following:


Then let’s modify user_row.xml. Add this to the ImageView:


While still in user_row.xml, let’s add a random last name to the TextView:


Now run the project, and see what we’ve created!

The finished result.

For further development, see this page on the Android Developer’s website.

About the author

Daniel Malone
Bringing more than a decade of software engineering experience, Daniel Malone is Editor at androidEveryday. An Austin native, Daniel is often found reading technical books, blogging and creating YouTube tutorials. When not working, he likes to listen to pop hits on Google Play Music.

Android RecyclerView Tutorial (Part 1)

  • Most apps contain lists of data using RecyclerView.
  • In this tutorial, use ConstraintLayout and Kotlin to display a list of data.

1 year ago

findViewById() in Kotlin

  • As you may have discovered, findViewByid() is no longer needed.
  • Kotlin adds the ability to directly access Views.

1 year ago

Android Architecture Components Tutorial: ViewModel + LiveData

  • Use Kotlin to build a basic Android app using Android Architecture Components.
  • As part of Jetpack, LiveData and ViewModel support a MVVM app architecture.

1 year ago