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

后端 未结 18 1742
小蘑菇
小蘑菇 2021-02-03 16:51

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 “Bindi         


        
18条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-03 17:14

    I ran into a similar issue that hasn't been mentioned here yet. In my case, I incorrectly added as the tag versus . is apparently a valid tag because Android Studio didn't complain (other than requiring layout_width and layout_height which aren't required for ). The capitalization difference will manifest in similar behavior where you cannot import the databinding class (import com.example.android.aboutme.databinding.ActivityMainBinding in my case) in the MainActivity class even though is a valid tag and the build.gradle file is defined properly to support data binding.

    In my case, I did not need the tags defined yet in order for ActivityMainBinding to validly import and be referenced in:

    private lateinit var binding: ActivityMainBinding

    I was working through the this codelab when I ran into this behavior: https://developer.android.com/codelabs/kotlin-android-training-data-binding-basics/index.html

提交回复
热议问题