Android RecyclerView and CardView Tutorial

Navjacinth Mathew
2 min readJan 12, 2017

In this tutorial we will start off RecylerView, it’s very similar to ListView, but RecyclerView is much more faster and efficient than ListView. In this particular example we will be generating a list of Employees using CardView & RecyclerView with custom adapter. If you are not familar with CardView you can check previous turorial. so let’s begin

Step 1 : Add the following dependency to your app level gradle

Step 2 : Let’s create the model class for employee using which we will be adding an arraylist of employees. Create a new java class and name it ‘Employee.java’. Add the following code to the file

Step 3 : Now we will create layout file that will be utilized by the adapter of the RecyclerView to generate each item in the list. Add a new file to your ‘layout’ folder and give the filename as ‘row_employee.xml’. Add the following code to your file

Step 4 : We will now create the adapter that will be used by the RecyclerView. Create a new java class in your package and name it EmployeeAdapter.java

Step 5 : Now we will add RecyclerView tags to activity_mail.xml

Step 6 : Now in MainActivity.java we will add 4 dummy Employee object into ArrayList which will be passed to the adapter ‘EmployeeAdapter.java’ while instantiating the adapter, then set the adapter to the RecyclerView. The code for MainActivity.java is given below

Now run your android application you should be able to see the output as shown below:

Get the project code at GitHub

--

--