开发者

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 开发者_Python百科the ListView that InputMethodManager sees.

Any suggestions how to solve this?


Have you tried something like this, apologies if you have

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜