Skip to content

Instantly share code, notes, and snippets.

@heinrisch
Created April 19, 2016 08:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heinrisch/d276c9fa69e04fc53b619444bad463e3 to your computer and use it in GitHub Desktop.
Save heinrisch/d276c9fa69e04fc53b619444bad463e3 to your computer and use it in GitHub Desktop.
private class LazyView<T>(view : View, res : Int) : ReadWriteProperty<Any?, T> {
private var mView: View = view
private var res : Int = res
private var mValue: T? = null
override fun getValue(thisRef: Any?, property: KProperty<*>): T {
mValue = mValue ?: mView.findViewById(res) as T
return mValue!!
}
override fun setValue(thisRef: Any?, property: KProperty<*>, value: T) {
throw UnsupportedOperationException()
}
}
var imageView by LazyView<ImageView>(this, R.id.imageview)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment