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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With