"下一步"按钮跳过"日期选取器"字段,只关注"编辑文本"



我有一个包含一些editText和datePiker的表单。当我按下next时填写表单,它会关注下一个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;
}
});

OR

添加此行以获得对微调器的关注

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);
}

确保使用日期选择器/微调器的可聚焦属性:

android:focusable="true"

尝试此方法在属性中设置焦点

android:nextFocusDown="@+id/etText1"  or android:nextFocusForward="@+id/etText1" 

android:imeOptions="actionNext"

最新更新