Q:

setOnClickListener not working android kotlin

I'm learning android and kotlin, and I'm building a practice app. When I run my code the button isn't working and i don't know why or what I'm doing wrong/forgot to add. Any help is appreciated!
My xml code:
 <Button
    android:id="@+id/solveBtn"
    android:layout_width="113dp"
    android:layout_height="65dp"
    android:layout_marginBottom="184dp"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:text="Solve" 
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.501"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/NumInput" />

and my kt code:
    class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)

    var num = NumInput.inputType.toInt()
    var answer = ansText

    fun solver (num1 : Int) {
        var div = 1
        var count = 0
        if ((num1 > 0) && (num1 < 2)){
            println("$num1 is a prime number!")
        } else{
            while (div < num1){
                if ((num1 % div) == 0){
                    div++
                    count++
                }else {
                    div++
                }
            }
        }
        if (count == 0) {
            answer.text = "$num1 is not a prime number"
        } else {
            answer.text = "$num1 is a prime number"
        }

    solveBtn.setOnClickListener{
        println("Hello")
        answer.clearComposingText()
        solver(num)
        }
    }
}

}
Again thanks for any help!

A:

Your solveBtn.setOnClickListener is inside the solver function which is never called. Just put setOnClickListener call one curly brace lower.

