this is in Kotlin, it doesn’t seem to work no matter what I try it’s just a button with a click listener. Its function is to take me to another activity, I tried a toast but didn’t show either. I tried not using the function and also didn’t work. and can we use this method with a text view? I’m new in Kotlin so easy on me…
here’s the code
val startButton = binding.loginButton
startButton.setOnClickListener {
fun crtUser() {
Toast.makeText(this, "It's Working!", Toast.LENGTH_LONG).show()
val intent = Intent(this@LoginActivity, SignupActivity::class.java)
startActivity(intent)
}
crtUser()
}
}
I also used finish() after the Intent, and it crashed
2
Answers
It's working now just after I changed this
To this
Any Idea Why??
Please do not use this syntax, it is not invalid, but improving it will be much better for you and for other developers to understand faster and easily what is going on :). Trigger the function from the on click event as follows:
And then you can have createUser() as an inner method of your current class:
Little tip: don’t abbreviate the methods names, you can use long name if needed as long as it improves the semantics of your code.
If it crashes, please, attach the Exception stack trace 😀