【问题标题】:Next button skips Date Picker field and only focuses on EditTextNext 按钮跳过 Date Picker 字段,只关注 EditText
【发布时间】:2019-04-30 07:48:53
【问题描述】:

我有一个包含一些editTexts 和datePiker 的表单。当我按下下一个时填写表单,它专注于下一个editText,但是当editText之间有日期选择器或微调器时,它们会被跳过并且它们之后的下一个editText被设置为焦点。有人可以帮我解决这个问题吗?

【问题讨论】:

  • 将焦点设置到特定视图集 android:nextFocusForward="@+id/view_you_want_to_have_focus" 到您在 xml 中的视图。

标签: android form-fields


【解决方案1】:
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);
}

【讨论】:

    【解决方案2】:

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

    android:focusable="true"
    

    【讨论】:

      【解决方案3】:

      试试这个方法在你的属性中设置焦点

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

      android:imeOptions="actionNext"
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-08-20
        • 2012-07-14
        • 1970-01-01
        • 2016-09-06
        • 1970-01-01
        相关资源
        最近更新 更多