Handle ENTER button Kotlin Android Studio

Sometimes you need to handle Enter button while make an application. To handle button in Kotlin Android Studio, you can just copy this kotlin code.

    //Handle Enter Button
    fun myEnter(){
        editText.setOnKeyListener(View.OnKeyListener{v, keyCode, event ->
            if (keyCode == KeyEvent.KEYCODE_ENTER && event.action == KeyEvent.ACTION_UP){
               //Start your action
                Toast.makeText(this, "Hi there ! \n This is a Enter Event Button", Toast.LENGTH_LONG).show()
                //End action
                [email protected] true
            }
            false
        })
    }

How to use, just call:

 myEnter()

Leave a Comment