how to catch 'next' button on soft keyboard of Android

拥有回忆 提交于 2019-12-04 23:04:39

问题


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


回答1:


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;
        }
    });



回答2:


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.



来源:https://stackoverflow.com/questions/14689932/how-to-catch-next-button-on-soft-keyboard-of-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!