-3

I want to bind "this" context to listener in kotlin

2 Answers2

0

In kotlin class you have to write the activity name with @ annotation in order to get the context of the class.

button.setOnClickListener {
val intent = Intent(this@MainActivity, PicturesActivity::class.java)
startActivity(intent)
}

or if you have override the onclick method just register the onclick method inside onCreateas

buttonX.onSetOnclickListener(this@ActivityName)
Raza
  • 791
  • 7
  • 22
-1

Here is an example on how to use the onClickListener in Kotlin

buttonX.setOnClickListener(object : View.OnClickListener{
        override fun onClick(v: View?) {
            //Code here ....
        })
Sandeep
  • 455
  • 4
  • 26