``` class TextDelegate(private val id: Int) : Read...
# android
k
Copy code
class TextDelegate(private val id: Int) : ReadWriteProperty<View,CharSequence> {
    override fun getValue(thisRef: View, property: KProperty<*>) = (thisRef.findViewById(id) as TextView).text

    override fun setValue(thisRef: View, property: KProperty<*>, value: CharSequence) {
        (thisRef.findViewById(id) as TextView).text = value
    }
}

val foo by TextDelegate(R.id.editTextFoo)