我正在使用onKeyListener来获取onKey事件.它可以正常使用普通键盘.但它不适用于软键盘.我只能获得数字而非字母的关键事件.有没有解决方法可以解决这个问题?任何形式的帮助将不胜感激.
我有一个EditText字段,变量名称valueInputField.
我听文本输入更改,我想要实现的是在输入过程中,当输入格式与正则表达式不匹配时,我想停止显示更多输入,但保持字段集中并且用户能够键入键盘仍然只是没有真正的效果将采取该领域.
@OnTextChanged(R.id.value_input)
protected void onTextChanged(CharSequence charSequence) {
String inputChars = charSequence.toString().trim();
// if doesn't match regular expression, stop showing more inputs
if (!inputChars.matches(MY_REGEXP)) {
// this doesn't achieve what I need.
valueInputField.setInputType(0)
}
}
Run Code Online (Sandbox Code Playgroud)
我试过上面的方法,它不起作用.如何实现我的需求?