View Binding

Like Butterknife Kotlin provides databinding.

Instead of:

val showCountTextView = findViewById(R.id.textView) as TextView

Kotlin allows:

textView
//when you need a view from a layout file, you can import the following
kotlinx.android.synthetic.main.<layout filename>.<id of view>
//or
kotlinx.android.synthetic.main.<layout filename>.*

Important: You will be able to reference any view that exists in your project with the ID of that view as a property. However, Kotlin can only create these properties from an inflated view. Using view IDs from a layout file that has not been inflated will throw a NullPointerException.

results matching ""

    No results matching ""