Home > OS >  Should we use Data Binding and View Binding on a single project?
Should we use Data Binding and View Binding on a single project?

Time:10-25

Suppose in a project I have 10 XML file. Within 3 of them don't require data binding feature i.e., we just need the reference of views, thus don't need to wrap all the three XMLs into <layout>...</layout> tag. So is it a good idea to use both view binding and data binding, or just the data binding as it's superior of view binding?

P.S: Wrapping up into <layout>...</layout> is not a big deal, but I am asking for best practices we should follow.

CodePudding user response:

Yes both can be used in a project for the UI where the data is linked to the data of the viewModels used it is preferred to use DataBinding and normally you should use ViewBinding as it is less resource intensive and efficient, lastly you can use both of them synonymously in project.

CodePudding user response:

The answer to your question is yes, you can use data-binding and view-binding together, but it's not recommended because it significantly impacts your build time. There is nothing view-binding can do that data-binding cannot.

You can check this link that compares these two approaches and explains the differences, but normally view-binding can be a better choice due to a lower build time and better effectiveness.

  • Related