Skip to content

Instantly share code, notes, and snippets.

@tsuharesu
Last active January 9, 2016 17:20
Show Gist options
  • Save tsuharesu/195ffa4c4d48aef8852e to your computer and use it in GitHub Desktop.
Save tsuharesu/195ffa4c4d48aef8852e to your computer and use it in GitHub Desktop.
Kotlin ViewBinder for Android
/**
* View binder with nullable types support
*/
class ViewBinder<M>(val function: (M) -> Unit) : ReadWriteProperty<Any, M> {
private var mValue: M? = null
override fun getValue(thisRef: Any, property: KProperty<*>): M {
return mValue as M
}
override fun setValue(thisRef: Any, property: KProperty<*>, value: M) {
mValue = value
function(value)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment