Created
December 16, 2020 12:36
-
-
Save tpakis/1d260b9cf08c0ce9869a63a0e70071a1 to your computer and use it in GitHub Desktop.
bindView extension methods
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
fun <T : View> Activity.bindView(@IdRes res: Int): Lazy<T> { | |
@Suppress("UNCHECKED_CAST") | |
return lazy(LazyThreadSafetyMode.NONE) { findViewById<T>(res) } | |
} | |
fun <T : View> View.bindView(@IdRes res: Int): Lazy<T> { | |
@Suppress("UNCHECKED_CAST") | |
return lazy(LazyThreadSafetyMode.NONE) { findViewById<T>(res) } | |
} | |
fun <T : View> RecyclerView.ViewHolder.bindView(@IdRes res: Int): Lazy<T> { | |
@Suppress("UNCHECKED_CAST") | |
return lazy(LazyThreadSafetyMode.NONE) { itemView.findViewById<T>(res) } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment