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

Ive Vasiljevic

12/05/2019, 1:22 PM
In which way is the new experimental ViewBinding feature better than Android Kotlin Extensions for accessing views, by their ID? Except for type safety and null safety, are there any speed improvements?
s

stantronic

12/05/2019, 1:45 PM
As I understand it, kotlin extensions are global, so there’s no checking for whether the view exists in the screen that you’re working on. I’m not aware of any significant speed or performance improvements, I think its mostly about safety. Although it is faster than DataBinding
g

ghedeon

12/05/2019, 10:07 PM
Not sure about significant runtime speed gain, but I'd be more concerned by getting slower build time instead.
t

tseisel

12/05/2019, 10:37 PM
I've read that ViewBinding traverse the view-tree only once to get references to all required views, while each
findViewById
requires a new traversal to find one View reference at a time. Since Kotlin Extensions are using
findViewById
under the hood (with a cache), ViewBinding might be more efficient.
a

Amirul Zin

12/06/2019, 12:54 AM
Since it was brought over from DataBinding, then it should be the same set of advantages as previously: 1. O(1) access to Views everytime, all the time. 2. Not having to mentally remember about having a View cache (and possibly buggy) implementation. 3. Null safety for multiple layout configs. 4. Auto included nested ids via
<include>
👍 1