Button setOnClickListener doesn't handle all clicks

Hi all,

I write simple code to handle user clicks, but sometimes use clicks on the button and no log message print in logcat and no toast on screen.

Here is the simple code:

class MainActivity : AppCompatActivity() {

    companion object {
        const val LOG_TAG = "MAIN-ACTIVITY"
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        bt_test.setOnClickListener {
            Log.d(LOG_TAG, "Scan button clicked.")
            Toast.makeText(this, "hey hey", Toast.LENGTH_SHORT).show()
        }
    }
}

Try this, set OnClick (e.g :btnClick) function in xml of that activity then pars your toast and log into btnClick into kotlin class after that call it into onCreate method

Thanks @uwe_van for your reply. The source of problem was from infinite loop that make UI non responsive.

Okay glad that solved