Kotlin has a number of Android Extensions and one ...
# android
i
Kotlin has a number of Android Extensions and one of them is that by referencing the ID of the view findViewById method is not necessary. And it is actually using cache so when you access that same view it is taken from cache. This works for Activity and Fragment classes, but when referencing a view by its ID from a custom class such as ViewHolder there is no cache and for every view in RecyclerView findViewById is called, so in that case I need to implement LayoutContainer interface on that class. So my question is, is this implementation still necessary in late 2019?
👌 1
t
In fact, the View cache of
Kotlin Android Extensions
have some known flaws and is expected to be replaced by the upcoming
ViewBinding
. I personally don't mind using
findViewById
in a ViewHolder.
r
Unless your view hierarchy is massive don’t bother with a cache. You should indeed look at ViewBinding instead.
1