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.buildaddapply 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_viewdirectly in your code.
How does it work? The first time that you call recycler_view, a call to findViewById is done and cached.