Reputation: 35
I am trying to build pretty much my first android app. I am also learning Kotlin at the same time. As it stands i can't seem to get activity transition to work.
This is the code of the main activity class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
PdfButton.setOnClickListener(View.OnClickListener{
@Override
fun onClick(v:View) {
val intent = Intent(this@MainActivity, WebActivity::class.java)
startActivity(intent)
} } )
}
}
And this is the code of the second activity
class WebActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_web)
}}
Any help would be deeply appreciated. Thank you in advance
Upvotes: 1
Views: 2835
Reputation: 360
In kotlin, you can simplify OnClicklisteners using lambda expressions. Try below code, it will work
PdfButton.setOnClickListener{
val intent = Intent(this@MainActivity, WebActivity::class.java)
startActivity(intent)
}
Upvotes: 2