Created
September 9, 2014 20:29
-
-
Save stepango/f0d25783ebbf4333c36e to your computer and use it in GitHub Desktop.
Android kotlin lazy view injector
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
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