setOnclickListener button is not working


#1

Hello guys i have a problem on click button

     fun mainPage(view: View) {
        val intent = Intent(applicationContext, MainActivity::class.java)
        intent.putExtra("input", userText.text.toString())
        startActivity(intent)
    }

   //second button started in here
     singupButton.setOnClickListener {
        fun crtUser (view: View) {
            val intent = Intent(applicationContext,createUser::class.java)
            startActivity(intent)
        }
    }

But i don’t get it the problem in there. When i done this another project which is changing the pages inside it was works perfectly.


#2

I don’t know the code, but it looks like you want to create an function inside a lambda?
If you just need to execute the code, maybe you can do it like this?:

    singupButton.setOnClickListener { view: View->
            val intent = Intent(applicationContext,createUser::class.java)
            startActivity(intent)
    }

#3

I turned the first code to like this and its works fine.

    val intent = Intent(applicationContext, MainActivity::class.java)
            intent.putExtra("input", userText.text.toString())
            startActivity(intent)

and for second one

        singupButton.setOnClickListener { view ->
                fun crtUser (view: View){
                val intent1 = Intent(applicationContext, createUser::class.java)
                startActivity(intent1)
        }
            crtUser(view)

they are works fine
Also thanks for feedback.