Check Mobile App
Read now
Start a Project

Data Binding Part IV: Recycler View with view swicher and data binding


Today we are going to learn the switching between list and grid view with data binding and recyclerview, as we have seen in many m-commerce sites.

We are going to use a static flag to check whether we have to inflate grid view or list view. The flag is intially set to list view (i.e static Boolean isGrid=false; ). You can do this by saving a value to the shared preferences.

Start by creating two xml file for two views (list and grid). You can create your own view file I had created the two as item.xml and item_grid.xml.

Now in main activity we need a view switcher we are using a imageview inside a FloatingAction Button.

And the activity will be like

Now the important part is creating adapter for both the views

And its ready. you can use any number of views but try to not make it so complicated by adding unnecessary views. So thats all about recycler view with data binding.


. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


  • Data Binding Part-III: Recycler view - Mobikul
    […] Next> […]
  • css.php

    When I think in getting solutions for my Ecommerce Platform, I think of Webkul. They have been such a blessing in our business. We have spent thousands of dollars in support and modules from them. We love their support team. They work very closely with us, and they always go the extra mile when we need help.

    Michael Urresta

    Michael Urresta

    Talk to Sales


    Live Chat
    Start a Project

      Message Sent!

      If you have more details or questions, you can reply to the received confirmation email.

      Back to Home