Kotlin synthetic in Adapter or ViewHolder

前端 未结 7 644
孤独总比滥情好
孤独总比滥情好 2020-12-13 05:36

I am new in kotlin. I have found and tried to use synthetic method instead of annoying method findViewById in my Activity class, but I have found \

7条回答
  •  攒了一身酷
    2020-12-13 06:06

    It means you have to place this line at the beginning of your source file:

    import kotlinx.android.synthetic.main.view.*
    

    So now instead of, for example, findView(R.id.textView) as TextView you would write just textView. The latter is a synthetic extension property located in the package kotlinx.android.synthetic.main.view, that's why you have to import everything from it.

    There's a tutorial on the official site, take a look.

提交回复
热议问题