选中复选框时立即在 editText 中显示键盘

Straight away show keyboard in editText when checkBox get checked

所以我在 activity.

中有一个 editTextcheckboxspinner

选中checkbox时,editText会显示,spinner会隐藏。

 public void addListenerOnTo() // for checkbox
    {

        checkBoxTo.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    travelTo.setVisibility(View.INVISIBLE); // spinner
                    addTo.setVisibility(View.VISIBLE); // editText

                } else {
                    travelTo.setVisibility(View.VISIBLE);
                    addTo.setVisibility(View.INVISIBLE);

                }
            }
        });
    }

如何在选中 checkbox 后直接输入而不按 editText 显示键盘?谢谢。

addTo.setVisibility(View.VISIBLE);

之后添加此代码
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(InputEditText, InputMethodManager.SHOW_FORCED);

这可以简单地通过将焦点设置在编辑文本上然后强制显示软键盘来实现!

  public void addListenerOnTo() // for checkbox
        {

            checkBoxTo.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    if (isChecked) {
                        travelTo.setVisibility(View.INVISIBLE); // spinner
                        addTo.setVisibility(View.VISIBLE); // editText

    // add this line to make the keyboard visible 

addTo.requestFocus();

InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);

                    } else {
                        travelTo.setVisibility(View.VISIBLE);
                        addTo.setVisibility(View.INVISIBLE);

                    }
                }
            });
        }

如果可行,请告诉我! :)