sowmia sowmia - 17 days ago 6
Android Question

Android - DataBinding - How and when the Binding classes will be generated?

DataBinding Guide States

By default, a Binding class will be generated based on the name of the layout
file, converting it to Pascal case and suffixing “Binding” to it.
The above layout file was activity_main.xml so the generate class was ActivityMainBinding.


When will the Binding class , here say ActivityMainBinding, will be generated. I have compile time error. "cannot resolve ActivityMainBinding".

ActivityMainBinding binding = DataBindingUtil.setContentView(this, R.layout.main_activity);


Any help is appreciated. Thanks

Mao Mao
Answer

What is your layout name?

The above layout file was activity_main.xml so the generate class was ActivityMainBinding.

What this means is that the generated class name will depend on your layout's name

activity_main.xml -> ActivityMainBinding.java

I think your activity name is "main_activity", so the generated binding class name should be MainActivityBinding not ActivityMainBinding

Comments