【问题标题】:A ListView in side an AlertDialog having an EditText field and it had focus but keyboard not getting popped up具有 EditText 字段的 AlertDialog 中的 ListView 具有焦点但键盘没有弹出
【发布时间】:2018-08-02 21:25:58
【问题描述】:

我有一个 AlertDialog 呈现多选列表视图,并且列表视图单行中有一个 editText。光标在闪烁,但没有软键盘弹出。

ArrayList<String> _items_ = new ArrayList<>(); _items_.addAll(Arrays.asList(_items));

    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    assert inflater != null;
    View view = inflater.inflate(R.layout.list_view_layout, null);

    final ListView listView = (ListView) view.findViewById(R.id.list_item);

    final SpinnerDialogAdapter spinnerDialogAdapter = new SpinnerDialogAdapter(context, R.layout.custom_spinner_layout, R.id.tv_attr, _items_, stringHashMap);
    listView.setAdapter(spinnerDialogAdapter);
    listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
    listView.setDivider(null);

    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setView(view);
    builder.setTitle("Please select");

    builder.setPositiveButton("Submit", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            HashMap<String, String> attrMapQty = spinnerDialogAdapter.getCheckedItemsQuantities();
            String stringName = spinnerDialogAdapter.getCheckedItemString();

            listener.selectedAttarQuantityMap(attrMapQty, stringName, pos, spAttribute, comment, selectedItem, attributes, rbIsSelected);
        }
    });
    builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {

        }
    });

    AlertDialog dialog = builder.create();
    dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
    dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);

    dialog.show();

【问题讨论】:

    标签: android listview android-edittext android-alertdialog android-softkeyboard


    【解决方案1】:

    您可以手动显示键盘:

    InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
    
    imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
    
    textView.requestFocus();
    

    【讨论】:

    • 请检查我刚刚在上面的问题中更新的图像。
    • 您的代码确实有帮助,但键盘在下方,当列表视图中有多个 editText 条目时,键盘甚至也不会弹出
    猜你喜欢
    • 1970-01-01
    • 2023-01-27
    • 2012-10-11
    • 1970-01-01
    • 2017-08-20
    • 2021-07-22
    • 2020-04-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多