setOnClickListener Ejemplo Kotlin
// set on-click listener
btn_click_me.setOnClickListener {
Toast.makeText(this, "You clicked me.", Toast.LENGTH_SHORT).show()
}
Vhern
// set on-click listener
btn_click_me.setOnClickListener {
Toast.makeText(this, "You clicked me.", Toast.LENGTH_SHORT).show()
}
text_view.setOnClickListener {
val intent = Intent(this@MainActivity, SecondActivity::class.java)
intent.putExtra("key", "Kotlin")
startActivity(intent)
}
// get reference to button
val btn_click_me = findViewById(R.id.btn_click_me) as Button
// set on-click listener
btn_click_me.setOnClickListener {
Toast.makeText(this@MainActivity, "You clicked me.", Toast.LENGTH_SHORT).show()
}