Redeem Now
Read More
Read now

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.


. . .

Comment (1)

Add Your Comment

  • Data Binding Part-III: Recycler view - Mobikul
    […] Next> […]
  • css.php
    Hire Us!
    Brief us about your requirements and we'll get back to you.
    Woo! Hooy!
    We have just recieved your project brief and our expert will contact you shortly.
    Send Again