https://kotlinlang.org logo
#android
Title
# android
v

vinny2020

07/20/2020, 6:54 PM
instead of findViewbyId
s

satyan

07/20/2020, 6:59 PM
On Slack you can edit the previous message instead of going full auto mode 😌 You can use View Binding to bind you view's layout.
findViewById
return a generic of type
View
so
val button: Button = findViewById(...)
or
val button = findViewById<Button>(...)
will provide you a
Button
(or crash at runtime if it's not a button). On the other hand View Binding (starting AGP 3.6) are type-safe, null safe (ex: a view present in a layout configuration and absent in another configuration).
v

vinny2020

07/20/2020, 7:18 PM
@satyan thank you!