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.

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 days 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 days 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.

6 days ago