我已经实现了一个注册活动,其中包含 viewpager 中的片段。在其中一个片段中,我有一个表单,其中包含一些动态创建的 EditText。问题是,如果我将输入类型数字或电话设置为此 EditText 之一,那么键盘将停止输入数字。如果我将输入类型设置为文本,那么它会按预期工作。
这是我设置输入类型的代码:
switch(mDatosSocio.getTipo()){
case "text":
etFormField.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_POSTAL_ADDRESS);
break;
case "number":
etFormField.setInputType(InputType.TYPE_CLASS_PHONE);
break;
case "email":
etFormField.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
break;
default:
break;
}
有什么想法吗?提前致谢!
编辑 解决方案
问题是我在父活动中有这个功能,所以它阻止了数字的输入。
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if (event.getAction()==KeyEvent.ACTION_DOWN) {
Log.d("KEYDOWN", event.getKeyCode()+"");
}
else if (event.getAction()==KeyEvent.ACTION_UP) {
Log.d("KEYUP", event.getKeyCode()+"");
}
Log.d("KEY", event.getKeyCode()+"");
return true;
}