Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

onClickListener to a keyboard button [closed]

I have a EditText field in my activity. The user can change the text in that field using the virtual keyboard. Once the user presses the enter key on the keyboard, I want to perform some action. So, how do I implement a setOnClickListener to the enter button on the keyboard?

like image 825
Ankush Avatar asked Dec 10 '25 15:12

Ankush


1 Answers

use onKeyListener for checking Enter press

for e.g..

edittext.setOnKeyListener(new OnKeyListener() {
    @Override
    public boolean onKey(View v, int keyCode, KeyEvent event) {
        if (event.getAction()!=KeyEvent.ACTION_DOWN)
            return false;
        if(keyCode == KeyEvent.KEYCODE_ENTER ){
            //your necessary codes...
            return true;
        }
        return false;
    }
});

for more information, check the official documentation

Also you can see that example

like image 64
Renjith Avatar answered Dec 12 '25 06:12

Renjith



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!