如何获取软键盘类型(QWERTY、(X)T9等)?
在一系列 EditText
视图中,在键入第 5 个字符后,光标应自动跳转到下一个视图。
我这样做:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
int twTreshold = 4;
etKey1 = (EditText) findViewById(R.id.et_levels_key1);
// ...
etKeyX = (EditText) findViewById(R.id.et_levels_keyX);
etKey1.addTextChangedListener(new TextWatcher() {
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (s.length() > twTreshold)
etKey2.requestFocus();
}
@Override
public void afterTextChanged(Editable arg0) {
if (currentText.length() > twTreshold)
etKey2.requestFocus();
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
});
}
现在的问题是: 用户可能使用 T9 或类似的键盘。在那里,为了输入字母“B”,必须按下键盘上的按钮“ABC”。 “A”连接到 EditText 的文本,触发事件 onTextChanged()
。太早了!用户仍然需要再次按下按钮“ABC”以将“A”替换为期望的“B”。
我的想法是获取键盘类型,如果它是此处提到的类型,则不要自动切换焦点。
有人知道如何检索键盘类型吗?
多谢!
In a series of EditText
views, the cursor should automatically jump to the next view, after the 5th character is typed.
I do this like that:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
int twTreshold = 4;
etKey1 = (EditText) findViewById(R.id.et_levels_key1);
// ...
etKeyX = (EditText) findViewById(R.id.et_levels_keyX);
etKey1.addTextChangedListener(new TextWatcher() {
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (s.length() > twTreshold)
etKey2.requestFocus();
}
@Override
public void afterTextChanged(Editable arg0) {
if (currentText.length() > twTreshold)
etKey2.requestFocus();
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
});
}
The problem now is:
The user might use a T9 or similar keyboard. There, in order to input the letter "B", the button "ABC" on the keyboard has to be pressed. An "A" is concatenated to the EditText's text, the event onTextChanged()
is fired. Too early! The user still has to press the button "ABC" another time to replace the "A" with a desired "B".
My idea was to get the keyboard type and, if it's of the type as mentioned here, just not to switch focus automatically.
Has someone maybe an idea how to retrieve the keyboard type?
Thanks a lot!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论