Skip to content

Instantly share code, notes, and snippets.

@liufsd
Forked from stepango/KotlinActivity
Created July 27, 2017 05:20
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 liufsd/9aa4a156e6a96c419fed1d01ac63a839 to your computer and use it in GitHub Desktop.
Save liufsd/9aa4a156e6a96c419fed1d01ac63a839 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