保持软键盘打开时进入关键是pressed [英] Keep soft keyboard open when enter key is pressed
问题描述
嗯,我从收盘试图prevent软键盘,当用户preSS的确定按钮编辑的文本字段后。 其实,我想要实现的是:当确定按钮是pressed,现场解析,如果有效,它开始另一个活动。 这是很容易的。
Well, I'm trying to prevent the soft keyboard from closing when the user press the "ok" button after editing a text field. Actually, what i'm trying to achieve is : when "ok" button is pressed, the field is parsed and if valid, it starts another activity. That is easy enough.
不过,当字段是无效的,我想软键盘保持打开状态。 这是......地狱更复杂。 如果有人知道如何实现这样的事情......
But, when the field is not valid, I want the soft keyboard to stay open. And that's... a hell more complicated. If anyone know how to achieve such a thing...
在此先感谢。
编辑:我的意思OK按钮是软键盘的OK按钮
EDIT : what I mean by the OK button is the OK button from the soft keyboard.
推荐答案
连接<一href="http://developer.android.com/reference/android/widget/TextView.OnEditorActionListener.html"><$c$c>OnEditorActionListener$c$c>你的文本字段,并返回真
从 onEditorAction
方法,当 actionId 的等于<一href="http://developer.android.com/reference/android/view/inputmethod/EditorInfo.html#IME_ACTION_DONE">IME_ACTION_DONE.这将prevent软键盘的隐藏:
Attach OnEditorActionListener
to your text field and return true
from its onEditorAction
method, when actionId is equal to IME_ACTION_DONE. This will prevent soft keyboard from hiding:
EditText txtEdit = (EditText) findViewById(R.id.txtEdit);
txtEdit.setOnEditorActionListener(new OnEditorActionListener() {
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
// your additional processing...
return true;
} else {
return false;
}
}
});
这篇关于保持软键盘打开时进入关键是pressed的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!