There are a lot of ways to access views in Android. A quick overview:
My advise would be:
- findViewById: old school. Avoid.
- ButterKnife: old school, but less boilerplate and some added functionality. Still lacks compile time safety. Avoid if possible.
- Kotlin Synthetic: really a elegant cached version of findViewbyId. Better performance and way less boilerplate but still no (real) compile time safety. Will be no longer supported from Kotlin 1.8. Avoid if possible.
- ViewBinding: Google’s recommendation nowadays. It’s faster than databinding and prevents logic errors inside XML (hard to debug). I use this option for all new projects.
- Data Binding: most versatile option, since it allows code inside XML. Still used on a lot of existing projects. But can slow down build times (uses annotation processor just like ButterKnife) and a lot of logic inside XML has become a bit of anti pattern.
See also: https://www.youtube.com/watch?v=Qxj2eBmXLHg
Funny to note that Jake Wharton (original author of ButterKnife) has now joined Google and works on ViewBinding.