I got your question and I think that you need to use viewBinding feature,
so the first step you need to enable viewBinding features in your gradle (module).
android{
buildFeatures {
viewBinding = true //this is mandatory
}
...
}
then you can bind your view
I use my code as example
inside the activity class
you can declare viewBinding of your activity using lateinit and inflate your activity inside onCreate fun
class HomeActivity : AppCompatActivity() {
private lateinit var binding: ActivityHomeBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityHomeBinding.inflate(layoutInflater)
setContentView(binding.root)
...
}
}
and finally you can easily access your view using binding val
example
binding.textView.text = "example"
the code above will be similar to
findViewById<TextView>(R.id.text_view).text ="example"