I am trying to make an application on android studio and I’m trying it for the first time. I can’t make any button clickable. I want to click a button and open another page. setonclicklistener is turning red when I write it. How can I make it work? I’m using Kotlin.
Question posted in Android Studio
The official documentation can be found here.
The official documentation can be found here.
2
Answers
If the whole
setOnClickListener
function has turned red in Android Studio, it means that you are trying to call it on a class/type that does not have that function, i.e. you are trying to callsetOnClickListener
on a class that does not extendView
. Check the error message and check the class/type that you are trying to callsetOnClickListener
on and make sure you are calling it on a Button (or any component that is extending a View, or a View itself).If you are new to Android (Kotlin) programming, check some tutorials for sample applications to get a quick introduction to the concepts that are unique to the Android programming environment.
In onCreateMethod you can simply write
You can also check https://stackoverflow.com/a/34593645/15529296