我注意到Kotlin合成属性在CustomViews上不起作用。我不知道是否有意。在读取生成的java类时,我看到缓存存在:
private HashMap _$_findViewCache;
但从未使用过。相反,只要需要视图,就会调用findViewById
。这是默认行为吗?合成属性仅适用于活动和片段?
答案 0 :(得分:2)
This works now. Blog post on kotlin-android-extensions
自定义类应生成缓存并使用它:
df <- structure(list(id = 10001:10010,
period = structure(c(1L, 2L, 1L, 1L, 2L, 1L, 2L, 1L, 2L, 1L),
.Label = c("2017-01", "2017-02"), class = "factor"),
year1 = c(2013, 2014, 2014, 2017, 1970, 2014, 1970, 2014, 2014, 1970),
year2 = c(2015, NA, 2015, 2015, 1970, 1970, 2014, 2017, 2014, 2017),
year3 = c(2015, 2014, 2015, NA, NA, 2014, 2014, 2015, 1970, 2014),
year4 = c(1970, 2014, 2013, 2014, 1970, 1970, 2014, 2015, 2015, NA)),
.Names = c("id", "period", "year1", "year2", "year3", "year4"),
row.names = c(NA, -10L),
class = "data.frame")
library(reshape2)
dcast(melt(df[,-1]), period + variable ~ value)
# period variable 1970 2013 2014 2015 2017 NA
# 1 2017-01 year1 1 1 3 0 1 0
# 2 2017-01 year2 1 0 0 3 2 0
# 3 2017-01 year3 0 0 2 3 0 1
# 4 2017-01 year4 2 1 1 1 0 1
# 5 2017-02 year1 2 0 2 0 0 0
# 6 2017-02 year2 1 0 2 0 0 1
# 7 2017-02 year3 1 0 2 0 0 1
# 8 2017-02 year4 1 0 2 1 0 0
这在自定义视图类中变为:
itemTitle.text = "Hello World!"
正确使用缓存