mxk
mxk

Reputation: 43524

Any painless way to trigger the soft keyboard for EditText in dialogs?

I am rendering an EditText as one element of a list-style AlertDialog (which is backed by the default ListView implementation). I sort of expected that this circumstance would not change the behavior of EditText, but it does: a click on the EditText does not spawn the soft keyboard anymore.

After an hour of messing around with focus settings and click handlers I got fed up and debugged into InputMethodManager.showSoftInput(), and found this:

    public boolean showSoftInput(View view, int flags,
        ResultReceiver resultReceiver) {
        ...
        if (mServedView != view && (mServedView == null
                || !mServedView.checkInputConnectionProxy(view))) {
            return false;
        }
        ...
    }
}

The problem here is that mServedView is the ListView that's backing the dialog, while view is the EditText, and ListView.checkInputConnectionProxy() does simply return false in the default implementation of ListView (to be overridden by subclasses).

Worse, I couldn't find a way to set a custom ListView which allows proxying IME requests; AlertDialog.Builder.setView() accepts a custom ListView, but this is not the ListView that InputMethodManager sees.

Any suggestions how to solve this?

Upvotes: 4

Views: 2425

Answers (2)

Donal Rafferty
Donal Rafferty

Reputation: 19826

Have you tried something like this, apologies if you have

getBaseContext().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);

Upvotes: 1

JERiv
JERiv

Reputation: 554

let me preface this with a big fat I KNOW NOTHING ABOUT THE ANDROID SDK.

That being said I would suggest: write a requestKeyboard throwable. have your EditText throw the requestKeyboard. This way the ListView can handle the throwable, generate the keyboard, then return the input to the edit text. This way mServedView == view

I think.

Upvotes: 0

Related Questions