Possible Duplicate:
Catch keypress with android
I want to execute some action when user press Enter button keyboard. How can I get this action?
Possible Duplicate:
Catch keypress with android
I want to execute some action when user press Enter button keyboard. How can I get this action?
Use the following code:
public boolean onKey(View v, int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_ENTER:
/* This is a sample for handling the Enter button */
return true;
}
return false;
}
and implement YourView.setOnKeyListener(this);
This was taken directly from this post.
Also you can use InputFilter:
InputFilter filter = new InputFilter()
{
public CharSequence filter(CharSequence source, int start, int end,
Spanned dest, int dstart, int dend)
{
for (int i = start; i < end; i++)
{
if (source.charAt(i) == '\n')
{
// Add whatever you want;
}
}
return null;
}
};