View fun onCreate(...) { titleText = findViewById(R.id.title_text) empty = findViewById(R.id.empty) } Access as: titleText empty Walks the view hierarchy to find view with matching id
var empty: View Butterknife.bind(this) Access as: titleText empty Generated injector code (“Butterknife is like a dagger, only infinitely less sharp”) Can also bind listeners, and other resources
viewBinding = DataBindingUtil.setContentView(this, R.layout.activity_main) Access as: viewBinding.title_text viewBinding.empty But mostly, instead, use databinding how it is actually meant (access data object via DSL from layout XML).
View.title_text: TextView inline get() = this.findViewById<TextView>(R.id.title_text) This is basically what you get with import kotlinx.android.synthetic.main.activity_main.view.*
View.title_text: TextView inline get() = this.findViewById<TextView>(R.id.title_text) This is basically what you get with import kotlinx.android.synthetic.main.activity_main.view.* Great for view holders, (fragments)
generated cache … which gets automatically cleared in Fragment.onDestroyView Great for activities, custom views, (fragments) - with experimental flag, also works for any class implementing kotlinx.android.extensions.LayoutContainer
Fragment, View, (LayoutContainer): import kotlinx.android.synthetic.$buildType.$layout_file_name.* (cached extension properties on the container) For inlined access on child views: import kotlinx.android.synthetic.$buildType.$layout_file_name.view.* (extension properties on View)