Home » Android RecyclerView List Example

Android RecyclerView List Example

by Online Tutorials Library

Android RecyclerView List Example

The RecyclerView class extends the ViewGroup class and implements ScrollingView interface. It is introduced in Marshmallow. It is an advanced version of the ListView with improved performance and other benefits. RecyclerView is mostly used to design the user interface with the fine-grain control over the lists and grids of android application.

In this tutorial, we will create a list of items with ImageView (for the icon) and TextView (for description) using RecyclerView and performs click listener on the item of its list.

Android RecyclerView with List Example

Create an Android project, and add the RecyclerView support library com.android.support:recyclerview-v7:23.1.0 or above this version in build.gradle file.

In the activity_main.xml file in layout directory, add the RecyclerView widget.


Create a dimens.xml file in values directory, and add the following code.


Create a custom layout list_item.xml file with following code.


Create a border.xml file in the drawable directory which is used to decorate the border of RecyclerView items.


Create a MyListData.java class with the following code. This class is used as (POJO) class which sets the properties of the items.


Create a MyListAdapter.java class and add the following code. This class extends RecyclerView.Adapter class and override its unimplemented methods. The onCreateViewHolder() methods inflates the list_item.xml. In the onBindViewHolder() method each data items are set to each row.


Finally, in the MainActivity.java class, add the following code. This class creates the array of items for MyListData class and set the adapter class to RecyclerView.



Android RecyclerView List Example Android RecyclerView List Example

You may also like