Skip to content

Instantly share code, notes, and snippets.

@tpakis
Created December 16, 2020 12:36
Show Gist options
  • Save tpakis/1d260b9cf08c0ce9869a63a0e70071a1 to your computer and use it in GitHub Desktop.
Save tpakis/1d260b9cf08c0ce9869a63a0e70071a1 to your computer and use it in GitHub Desktop.
bindView extension methods
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