androidandroid-4.0-ice-cream-sandwichandroid-softkeyboardandroid-4.2-jelly-beansearchview

Unable to show keyboard automatically in the SearchView


The SearchView is focused by default, but when I try to show software keyboard - it doesn't happen:

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

But when I click on the SearchView - it does. Why?


Solution

  • Fixed!

    mSearchView.setOnQueryTextFocusChangeListener(new OnFocusChangeListener() {
                            @Override
                            public void onFocusChange(View view, boolean hasFocus) {
                                if (hasFocus) {
                                    showInputMethod(view.findFocus());
                                }
                            }
                        });
    

    And

    private void showInputMethod(View view) {
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            if (imm != null) {
              imm.showSoftInput(view, 0);
            }
        }