我要重写的行为 ENTER 虚拟键盘的键,以便:
I want to override the behaviour of the ENTER key of the virtual keyboard so that:
当有屏幕上的更多领域,这片下一个字段 当它是屏幕的最后一个字段,它执行的屏幕的默认操作我一直在玩的IME选项和标签,但只是没有得到我想要的。任何人有什么建议?
I've been playing with the IME options and labels, but just don't get what I want. Anybody have any suggestions?
通过在另一个论坛的帮助下,我发现这样做的方式。
With help on another forum, I found the way to do it.
要使它可重复使用的,我已经创建了一个包含2 OnKeyListener
对象和抽象方法提出我自己的超级对话框类:
To make it reusable, I have created my own super dialog class that contains 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);