-
-
Save liufsd/9aa4a156e6a96c419fed1d01ac63a839 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