Read More
Read now

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

Save

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.

Next>>

. . .

Leave a Comment

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


1 comments

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

    Big thanks to Webkul and his team for helping get Opencart 3.0.3.7 release ready!

    Deniel Kerr

    Owner and Founder. Opencart

    Talk to Sales
    Start a Project

      Message Sent!

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

      Back to Home