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:

tools:listitem="@layout/user_row"

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

tools:src="@tools:sample/avatars"

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

tools:text="@tools:sample/last_names"

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.

Daniel Malone 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.

2 years ago

findViewById() in Kotlin

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

2 years 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.

2 years ago

Android SharedPreferences Tutorial in Kotlin

  • Use SharedPreferences to store simple data in Android Studio projects.
  • It's good for storing small amounts of data

    2 years ago

Cleaner Architecture for Android Apps

  • Clean Architecture for Android can help developers prepare for change.
  • But app developers can't possibly know what will change.

    2 years ago

Android RecyclerView with Kotlin – Part 3

  • In part three of this series, finish creating the RecyclerView.
  • Use onBindViewHolder to display data.

2 years ago

Android RecyclerView with Kotlin – Part 2

  • Create the entire RecylerView for our UsersAdapter.
  • Continued from part 1, where we set up the Android Studio project.

2 years ago

Android and RxJava: Using a Single

  • Use RxJava's Single class when the expected type is either a success or error.
  • It's only slightly different from Observable.just(), which we discussed in the last article.

2 years ago

Android and RxJava: Getting Started

  • The powerful library RxJava can help developers build better apps.
  • See how to use Observables and Observers in this tutorial.

2 years ago

Android RecyclerView with Kotlin - Part 1

  • Oftentimes, developers need to display a list of some sort of data.
  • Whatever type of data is displayed, you should use a RecyclerView.

2 years ago

Android Studio Tutorial with Kotlin (2018 Edition) - Part 2

  • Create a UI in Android Studio using the Design mode.
  • In this latest installment for beginners, we'll add a widget to our screen.

2 years ago