tags:

views:

740

answers:

2

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 reuqests; AlertDialog.Builder.setView() accepts a custom ListView, but this is not the ListView that InputMethodManager sees.

Any suggestions how to solve this?

A: 

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.

JERiv
wicked idea, but I'm pretty sure that throwing anything inside a onFocus/onClick handler will simply terminate your app.
Matthias
+1  A: 

Have you tried something like this, apologies if you have

getBaseContext().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
Donal Rafferty
Frankly, I don't remember :-) I'm not working on that project ATM, but I'll have another look by then. Thanks for the idea anyhow!
Matthias