Created
April 19, 2016 08:44
-
-
Save heinrisch/d276c9fa69e04fc53b619444bad463e3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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