Build List Using RecyclerView In Android


Android RecyclerView with List Example –

First Create an Android Project with empty activity and open activiity_main.xml file in layout folder. After that add the RecyclerView widget.


Now we have to create a custom layout for listing items, So create list_layout.xml and add following code.


After creating list layout we need to create class. This class is used to sets the properties of the items.

So now create class. This class extends RecyclerView.Adapter class and its methods like onCreateViewHolder() and onBindViewHolder(). onCreateViewHolder method inflates your list_layout.xml and the onBindViewHolder() method set each data items in list_layout.xml, also if you want to add a click event on any item then also you can do that in this method.


Now it’s time to write some code in class. In this class, we create an array of items for Listdatamodel class and set the adapter class to RecyclerView.