android - Next 按钮跳过 Date Picker 字段,只关注 EditText
问题描述
我有一个包含一些editTexts 和datePiker 的表单。当我按下下一个时填写表单,它专注于下一个editText但是当editText之间有日期选择器或微调器时,它们会被跳过并且它们之后的下一个editText被设置为焦点。有人可以帮我解决这个问题吗?
解决方案
editTextBefore.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_NEXT) {
hideKeyboard();
textView.clearFocus();
spinner.requestFocus();
spinner.performClick();
}
return true;
}
});
或者
添加此行以专注于微调器
Spinner spinner = (Spinner) findViewById(R.id.my_spinner);
spinner.setFocusable(true);
spinner.setFocusableInTouchMode(true);
spinner.requestFocus();
您还需要隐藏键盘,您可以使用以下方法执行此操作
private void hideKeyboard() {
InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(),
InputMethodManager.HIDE_NOT_ALWAYS);
}
推荐阅读
- arkit - generateCollisionShapes() 似乎不起作用
- c++ - 无论我运行同一个应用程序多少次,应用程序(.exe)中的函数都应该只调用一次
- linux - 将字符串添加到 awk 命令的末尾
- c++ - 函数返回错误的结果。查找 n 阶乘的最后一个非零数字
- python - SQL Alchemy & Docker Compose:最大递归错误
- c# - C#过滤来自restclient的json结果
- scalatest - 套装似乎没有执行嵌套套装
- javascript - 为什么Javascript在显示的数组元素中添加函数名称
- html - 如何纠正光滑滑块中的箭头?
- laravel - 无法在 Laravel 应用程序中解析 Postcss-loader