Я пытаюсь найти лучший способ привязки Android View Binding в Kotlin. Похоже, есть несколько вариантов:
findViewById
val button: Button by lazy { findViewById<Button>(R.id.button) }
Масляный нож
https://github.com/JakeWharton/butterknife
@BindView(R.id.button) lateinit var button: Button
Расширения Kotlin для Android
https://kotlinlang.org/docs/tutorials/android-plugin.html
import kotlinx.android.synthetic.main.activity_main.*
Я хорошо знаком с findViewById и Butterknife в Java Land, но каковы плюсы и минусы каждого подхода к привязке представления в Kotlin?
Хорошо ли работают расширения Kotlin для Android с шаблоном RecyclerView + ViewHolder?
Также как Kotlin Android Extensions обрабатывает привязку представлений для вложенных представлений через include
?
Пример: для Activity, использующего activity_main.xml
, как будет доступен View custom1
?
activity_main.xml
<...>
<include layout="@layout/custom" android:id="@+id/custom" />
</>
custom.xml
<...>
<View android:id="@+id/custom1" ... />
<View android:id="@+id/custom2" ... />
</>