Android one activity to another activity, Display Toast - kotlin
First create button with id button1 in XML file. Then write the code in onCreate in kotlin file.
This will go from MainActivity to MainActivity2.
val button1 = findViewById<Button>(R.id.button1)
button1.setOnClickListener {
Toast.makeText(this@MainActivity, "Button 1 Clicked", Toast.LENGTH_SHORT).show()
val intent = Intent(this, MainActivity2::class.java)
startActivity(intent)
}
No comments