Android - How to achieve setOnClickListener in Kotlin?

Anirudh Agarwal picture Anirudh Agarwal · Jun 1, 2017 · Viewed 116.7k times · Source

I wanted to know that how we set basic onClickListener in Kotlin for Android Development.

Answer

Vinod Pattanshetti picture Vinod Pattanshetti · Jun 1, 2017

Suppose you have textView to click

text_view.text = "Hello Kotlin";

text_view.setOnClickListener {
    val intent = Intent(this@MainActivity, SecondActivity::class.java)
    intent.putExtra("key", "Kotlin")
    startActivity(intent)
}