how to catch 'next' button on soft keyboar

2020-06-17 06:48发布

I have 6 Edittexts grouped in 6 differents layouts, all in the same view. My problem is that my app is forced to landscape mode, and by pressing the 'next' button i want to automatically start to edit another editText rather than the one android set me by default. Example: i'm writing on EditText1, press next, and focus is taken by the EditText that is UNDER the 1st one. I want to edit the one that is RIGHT to it.

Sorry for my bad english :( The device is a galaxy tab, with Google API8/Android 2.2 Thanks

2条回答
ゆ 、 Hurt°
2楼-- · 2020-06-17 07:19

Haven't tested it, but this should work

 some_edittext.setOnEditorActionListener(new OnEditorActionListener() {
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_NEXT) {
                some_button.performClick();
                return true;
            }
            return false;
        }
    });
查看更多
够拽才男人
3楼-- · 2020-06-17 07:45

I might be wrong but I don't think there is any implicit way of doing it. You would need to write your own EditorAction.

You need to monitor everything that the user enters and whenever he presses 'NEXT', you would have to manually shift the focus to the next EditText, using EditorInfo.IME_ACTION_NEXT.

查看更多
登录 后发表回答