1

I've researched many answers on SO and come up with the following code to show the keyboard when my Dialog pops up:

final AlertDialog alertDialog = new AlertDialog.Builder(this).create();
    alertDialog.setTitle("Title");
    final EditText input = new EditText(this);
    input.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View view, boolean focused) {
            alertDialog
                    .getWindow()
                    .setSoftInputMode(
                            WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);

        }
    });
    input.setFocusable(true);
    input.requestFocus();
    alertDialog.setView(input);

            alertDialog.show();

The dialog Shows, but the keyboard doesn't pop up. This is all within an onTouch(...) method if that makes a difference.

My app is landscape mode only. I find that in portrait mode, it is showing. Why is this?

Any help is appreciated.

Kgrover
  • 2,106
  • 2
  • 36
  • 54

1 Answers1

0

It looks like it was landscape mode that was throwing me off. The following piece of code solved the problem immediately:

imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,
                        InputMethodManager.HIDE_IMPLICIT_ONLY);
                imm.showSoftInput(input, InputMethodManager.SHOW_FORCED);
                alertDialog
                        .getWindow()
                        .setSoftInputMode(
                                WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
Kgrover
  • 2,106
  • 2
  • 36
  • 54