Create a custom List with RecyclerView using CardView

RecyclerView is a UI (user interface) component of Android app. With it, you can show a list of item in Horizontal, Vertical, grid and segregated manner. For an example, If you have to show a list of data sets then you can use RecyclerView. The RecyclerView widget is a more advanced and flexible version of ListView. In this example, we are going to use simple RecyclerView with a custom layout (Vertical scroll).

Create a custom List with RecyclerView using CardView


Let’s Build a Simple app for List with RecyclerView

This example, we will show the simple item in the list. This item has generated in dynamically using a loop.


Step 1. Create new project follow this tutorial
Step 2. Add design library in build.gradle (Module app)

it’s for RecyclerView API and its updating time to time please check with google doc or add from “open modules settings

Step 3. Add RecyclerView in activity_main.xml file

The Recycler view

Note : “@color/colorGrey” is added in res/values/color.xml resources, in <resource> tag


Step 4. create new XML file row_user.xml (for items in the list) and add following code.

Add TextView in CardView (you can add more widget in a row)

Step 5.  Create model class

Add variables int id and String login and generate Getter and setter.

Step 6. Create adapter class Myadapter.class

The adapter class is a bridge between a data and view.

Step 7. final add following code in MainActivity

It’s an Activity class where all thing is done like creating data and pass data to UI using adapters.

Step 8. Now Run the application, in an emulator or On your Android device

Output: custom List with RecyclerView using CardView

Android recycleview example


Download source code android RecyclerView and source code


Note : This example (Project) is developed in Android Studio 3.0.1 ,tested on Android 7.1.1 ( Android Nougat), build-tools version API 27+: Android API 27, P preview (Preview)



Coding in JAVA

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.