Programming Java, we need to use findViewById function to access a view item, nowadays in Kotlin we simply use id for accessing view item, like if we have a textView with id "myTxt" we simply use myTxt.text = "Some Text"
In the other hand using findViewById function in Java would led to less efficient performance, so we're suggested to use binding view for performance improvements
now the question is:
Now that we do not use
findViewByIdin kotlin, should we use binding, or this won't cause any efficiency in performance?
There are three common ways to get view references:
findViewByIdI think you are mixing up view binding vs. synthetic view properties.
When you say in Kotlin we "simply use id", that is called synthetic view properties. That feature was created for convenience over findViewById, not for performance.
Google at some point removed references to synthetic view properties in their documentation, because it is Kotlin-only. It's also not great that they are not null-safe or type-safe. Null safety is usually expected in Kotlin code. And all the synthetic properties for all your views are available from anywhere, regardless of whether they are in the current layout.
Later, they added view binding as a Jetpack feature. This is also not added for performance, but convenience. It's preferable to findViewById because it's null-safe, type-safe, and gives you properties for the exact views that you have inflated, nothing more or less. View binding is not limited to Kotlin. You can use it in Java.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With