0

Possible Duplicate:
Catch keypress with android

I want to execute some action when user press Enter button keyboard. How can I get this action?

Community
  • 1
  • 1
Winte Winte
  • 753
  • 5
  • 11
  • 24

2 Answers2

0

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.

Community
  • 1
  • 1
coder
  • 10,460
  • 17
  • 72
  • 125
0

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;
    }
};
Artyom Kiriliyk
  • 2,513
  • 1
  • 17
  • 21