Thanks, this works, it does catch the <enter> key.

Just for the other curious, here is how I use it now. I have created
my own super dialog class that has 2 OnKeyListener objects and an
abstract submit method:

public abstract class MyAbstractDialog extends Dialog {

        /**
         * OnKeyListener that puts the focus down when the ENTER key is
pressed
         */
        protected View.OnKeyListener onEnterFocusDown = new
View.OnKeyListener() {

                @Override
                public boolean onKey(View v, int keyCode, KeyEvent event) {
                if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
                            (keyCode == KeyEvent.KEYCODE_ENTER)) {
                                v.requestFocus(View.FOCUS_DOWN);
                        return true;
                }
                        return false;
                }
        };


        /**
         * OnKeyListener that submits the page when the ENTER key is pressed
         */
        protected View.OnKeyListener onEnterSubmitView = new
View.OnKeyListener() {

                @Override
                public boolean onKey(View v, int keyCode, KeyEvent event) {
                if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
                            (keyCode == KeyEvent.KEYCODE_ENTER)) {
                                submitView(v);
                        return true;
                }
                        return false;
                }
        };
        protected abstract void submitView(View v);
}

Now in the Dialog I can use these objects to set on my fields:


        // make the ENTER key on passwordField1 put the focus on the next
field
        passwordField1.setOnKeyListener(onEnterFocusDown);

        // make the ENTER key on passwordField2 submit the page
        passwordField2.setOnKeyListener(onEnterSubmitView);

-- 
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