Created
September 8, 2017 15:28
-
-
Save hluhovskyi/51d869695bb8ae619e4d5dc15c7fdde7 to your computer and use it in GitHub Desktop.
This file contains 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
class ViewFinderDelegate<T : View> : ReadOnlyProperty<Activity, T> { | |
private object EMPTY | |
private val id: Int | |
private var view: Any? = Empty | |
constructor(@IdRes id: Int) { | |
this.id = id | |
} | |
@Suppress("unchecked_cast") | |
override fun getValue(ref: Activity, property: KProperty<*>): T { | |
if (value == EMPTY) { | |
value = ref.findViewById(id) | |
} | |
return value as T | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment