Hi all,
So basically I found code where You can make pure, clean and lazy view bind:
private fun <T : View> Activity.bind(@IdRes res: Int): Lazy<T> {
@Suppress("UNCHECKED_CAST")
return lazy { findViewById(res) as T }
}
usage is simple:
private val resultBox: EditText by bind(R.id.resultBox)
So i came up with idea for multi bind ( using array of id’s) :
private fun <T : View> Activity.bind(@IdRes resources: Array<Int>): Array<Lazy<T>> {
return resources.map { bind<T>(it) }.toTypedArray()
}
And usage ex:
private var buttons: Array<Lazy<Button>> = bind(arrayOf(R.id.bttn4, R.id.bttn0))
This topic was previously a question, but it appeared to be very goofy type error. So I changed title for multi bind as it is the most relevant one if somebody will be searching for such a thing.
Thanks