Try something like:
val recyclerView = findViewById<RecyclerView>(R.id.recycler_view)
You can use Kotlin Android Extensions
too for that. Check the doc here.
With it, you can call recycler_view
directly in your code.
Kotlin Android Extensions:
- In your app
gradle.build
add apply plugin: 'kotlin-android-extensions'
- In your class add import for
import kotlinx.android.synthetic.main.<layout>.*
where <layout>
is the filename of your layout.
- That's it, you can call
recycler_view
directly in your code.
How does it work? The first time that you call recycler_view
, a call to findViewById
is done and cached.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…