Since I discovered the use of view binding by enabling
buildFeatures {
viewBinding true
}
in my gradle file, I never used findviewById in my code again. I wonder now if there is a cons to doing things this way. If this is the best method, why does android studio not enable this option by default when creating a new project? If not, when should I avoid using view binding? thank you.
Once you enable it for a project, view binding will generate a binding class for all of your layouts. That's the only "con" I see, it just generates more code, so it would increase the size of the project, compile time, etc. While it won't be a huge difference for projects with very little layouts, it could change significantly for larger projects.
Here's a very interesting read about ViewBinding performance : https://blog.stylingandroid.com/view-binding-performance/