Skip to content

Instantly share code, notes, and snippets.

@lordcodes
Last active February 4, 2020 08:00
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 lordcodes/1aa90e8a1815e0ac53ed3b75032155f2 to your computer and use it in GitHub Desktop.
Save lordcodes/1aa90e8a1815e0ac53ed3b75032155f2 to your computer and use it in GitHub Desktop.
Code for article "Using Kotlin to bind Android views"
fun <ViewT : View> Activity.bindView(@IdRes idRes: Int): Lazy<ViewT> {
return lazyUnsychronized {
findViewById<ViewT>(idRes)
}
}
class PlanningActivity : AppCompatActivity() {
private val planningText by bindView<TextView>(R.id.planning_text)
// or
private val planningText: TextView by bindView(R.id.planning_text)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment