Sectioned RecyclerView Android

Sectioned RecyclerView Android

Hi all, Today we are going to learn how to make Sectioned RecyclerView which you have seen in PlayStore App. To know about RecyclerView and basic implementations you can see my previous articles on it.

To make Sectioned RecyclerView we are going to need a RecyclerView nested into another RecyclerView.

VIDEO

1. Create a new project in Android Studio by navigating to File ⇒ New Android ⇒ Application Project and fill required details. By default my activity is MainActivity.java.

2. Open res ⇒ values ⇒ strings.xml and add below string values. These are some strings that we are going to use in our project.

3. Now go to activity_main.xml and add the below code to it. In this layout we are using three Button to show different types of Sectioned RecyclerView.

4. After adding three Button lets implement click event on them and open RecyclerViewActivity.java on Button click. For this add the below code to your MainActivity.java.

5. For RecyclerViewActivity.java create new xml layout naming recycler_view_activity.xml and add RecyclerView to it.

6. After creating recycler_view_activity.xml create RecyclerViewActivity.java class and put the below code to it. In this class we are populating RecyclerView with Sections and Items using SectionModel.java pojo class.

Vertical Sectioned RecyclerView

Vertical Sectioned RecyclerView

Horizontal Sectioned RecyclerView

Horizontal Sectioned RecyclerView

Grid Sectioned RecyclerView

Grid Sectioned RecyclerView

7. To identify the type of Sectioned RecyclerView we will create an ENUM java class naming RecyclerViewType.java and add the three enums to it.

8. Now create pojo class naming SectionModel.java for RecyclerView.

9. Now lets create adapter class for RecyclerView naming SectionRecyclerViewAdapter.java and put the below code to it. In this class we are setting different LayoutManager on basis of enum type inside onBindViewHolder method.

10. For RecyclerView sections we are going to create xml layout naming section_custom_row_layout.xml. This layout contains one section label, one show all button and one RecyclerView for displaying Section Items.

11. To display section items we need to create one more adapter for Items naming ItemRecyclerViewAdapter.java and put the below code to it.

12. For items adapter we need to create an xml layout naming item_custom_row_layout.xml. In this layout we are taking a CardView with ImageView and TextView.

13. Finally all done, now you can also make Sectioned RecyclerView.

Thanks. :)

Download Source Code – >

About the author

I am an Android developer for whom Android is the one and only love. I work as a freelancer which gets me and Android closer. I always love to share my learnings and love to learn from others knowledge too.

Leave a Comment

Comment (required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

Name (required)
Email (required)