Kotlin Synthetic Properties

I noticed that the synthetic properties of Kotlin do not work in CustomViews. I do not know if it is intended or not. When reading the generated java class, I see that the cache is present:

private HashMap _$_findViewCache;

but never used. Instead, when a view is required, it is called findViewById. Is this the default behavior? Do synthetic properties only work on actions and fragments?

+4
source share
1 answer

It works now. Kotlin-android extension blog post

The user class must have a generated cache and use it:

itemTitle.text = "Hello World!"

this in the custom view class becomes:

((TextView)this._$_findCachedViewById(id.itemTitle)).setText((CharSequence)"Hello World!");

use cache correctly

+2

Source: https://habr.com/ru/post/1669370/


All Articles