Is there any painless way to launch a soft keyboard for EditText in dialogs?

I present EditText as one element of the AlertDialog list AlertDialog (which is supported by the default implementation of ListView ). I did not seem to expect this circumstance to change the behavior of EditText, but it does: clicking on EditText no longer spawns a soft keyboard.

After an hour of clutter with the focus settings and click handlers, I got tired and debugged in 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 is that mServedView is a ListView that supports dialogue, while view is EditText and ListView.checkInputConnectionProxy() makes it simply return false in the default implementation of ListView (must be overridden by subclasses).

Worse, I could not find a way to configure my own ListView, which allows you to proxy IME requests; AlertDialog.Builder.setView() accepts a custom ListView, but it is not a ListView that sees InputMethodManager.

Any suggestions how to solve this?

+4
source share
2 answers

Have you tried something like that, apologize if you have

 getBaseContext().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); 
+1
source

Let me preface this with a lot of fat, I DO NOT KNOW ANYTHING ABOUT ANDROID SDK.

Having said that, I would suggest: write a request. let your EditText throw requestKeyboard. In this way, a ListView can handle throwable, generate a keyboard, and then return input to the edit text. So mServedView == view

I think.

0
source

All Articles