Skip to content

Instantly share code, notes, and snippets.

@stepango
Created September 9, 2014 20:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save stepango/f0d25783ebbf4333c36e to your computer and use it in GitHub Desktop.
Save stepango/f0d25783ebbf4333c36e to your computer and use it in GitHub Desktop.
Android kotlin lazy view injector
class KotlinActivity : Activity() {
val btn: Button? by find(R.id.button)
override fun onCreate(savedInstanceState: Bundle?) {
super<Activity>.onCreate(savedInstanceState)
setContentView(R.layout.main)
btn?.setText("Hello from kotlin")
}
fun <T : View?>find(id: Int) = Delegates.lazy { findViewById(id) as T }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment