Im a beginner in Android Studio and have a school project where I have to create an login screen with password and username. When trying to follow some instructions online I get an error even though I have done the same as the instructor. Can you see what I have done wrong?
Asked
Active
Viewed 969 times
-1
-
This is the video im trying to copy. And i get unresolved reference new when trying to do the same. See video from 19:00 https://www.youtube.com/watch?v=LCrhddpsgKU – Ulrik R Dec 01 '21 at 15:44
2 Answers
0
Your code is in Kotlin while the video you linked uses Java, so the error indicates that the onClickListener
is not following Kotlin syntax properly.
The equivalent in Kotlin is:
logIn.setOnClickListener {
// Do some work here
}
or
logIn.setOnClickListener(object : View.OnClickListener {
override fun onClick(view: View?) {
// Do some work here
}
})
Both will behave similarly. See alternative ways here.

cmak
- 576
- 1
- 4
- 15
0
// declare
private lateinit var logIn: Button
// cast
logIn = findViewById(R.id.logIn)
// execute the func you want
logIn.setOnClickListener {
executeLogInApi()
}

Elio Lako
- 1,333
- 2
- 16
- 26