How about something like this:

public class myClass extends Activity implements OnKeyListener {

private EditText mInput;

@Override
public void onCreate(Bundle savedState) {

//set layout and initialize mInput and set the keyListener to 'this'


}

@Override
public boolean onKey (View v, int keyCode, KeyEvent event) {

   switch (event.getKeyCode()) {

        case (KeyEvent.KEYCODE_ENTER) :
              myFunc();
              return true;
    }

   return false;
  }

}

On Feb 6, 1:54 am, ashu <[email protected]> wrote:
> I have a user input box that I want to execute a function every time I
> press enter.  I can't call super.onKey(...) to do the standard text
> input.
>
> I have two ways to solve this problems, but I'm having trouble looking
> for places to find out how to do this.
> 1. Convert the keycode to a character that I can append to (theText)
> 2. Find a standard onKeyListener that I can call
>
> ---------------------------------------------------------------------------------------------------------------------------
> final EditText userInputBox = (EditText) findViewById
> (R.id.editTextItems);
>         userInputBox.setOnKeyListener(new OnKeyListener()
>         {
>                 public boolean onKey(View v, int keyCode, KeyEvent event)
>                 {
>                     // code
>                         Editable theText = userInputBox.getText();
>                         int pressedKey = event.getUnicodeChar();
>                         if (pressedKey == '\n')
>                         {
>                                 addUserInput();
>                         }
>
>                         return true;
>                 }
>         });
> ---------------------------------------------------------------------------------------------------------------------------
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to