Closed alexfinnarn closed 5 years ago
Taken from: https://developer.android.com/topic/libraries/data-binding/expressions
A binding class is generated for each layout file. By default, the name of the class is based on the name of the layout file, converting it to Pascal case and adding the Binding suffix to it. The above layout filename is activity_main.xml so the corresponding generated class is ActivityMainBinding. This class holds all the bindings from the layout properties (for example, the user variable) to the layout's views and knows how to assign values for the binding expressions.The recommended method to create the bindings is to do it while inflating the layout, as shown in the following example:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val binding: ActivityMainBinding = DataBindingUtil.setContentView(
this, R.layout.activity_main)
binding.user = User("Test", "User")
}
Now I don't feel so bad since the binding classes are kinda "magic" that happens behind the scenes. When I first created the layouts, I didn't have data binding enabled and so Android Studio didn't create the classes for me.
I had to sort through the answers to https://stackoverflow.com/questions/39483094/data-binding-class-not-generated and try them one by one. For whatever reason, taking the namespace declarations out of the parent layout wrapper did the trick.
No idea why other than Android Studio recognized those layouts as being "new" when the namespaces were removed.
I screwed this up some how and now can't find the binding classes to faciltate inflation.