开发者

AlertDialoug focusing on EditText when dismissed.. causing Keyboard to appear.. what to do?

I am using an AlertDialog to pop up and ask the user for some information, when the user clicks on a button.

The dialog is working fine, and I get the user info it dismisses itself.

However when the app returns focus to my primary view.. it is setting the focus to an EditText widget which causes the keyboard to appear for that View.

I don't want the Keyboard to appear unless the user explicitely puts focus on that field, so how do I change/override the default behavior, so that it doesn't autofocu开发者_开发百科s on this field after the AlertDialog is dismissed.

It doesn't behave this way when the view initially inflates, the field is focused (highlighted), but the keyboard is not visible, only after the user taps on the field does the keyboard come up when the app launches. This behavior after dialog dismiss is completely different.. any ideas?

(No the EditText is not anywhere near the buttons of the alert dialog, so its not as though a second tap or something is happening accidentally or the click is being passed up the stack.)


Try doing this after the dialog is dismissed:

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);


You can ask the InputMethodManager to resign the keyboard when you dismiss the dialog:

EditText mValue; //The input view in your Dialog

//Close the keyboard
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(mValue.getWindowToken(), 0);

Hope that Helps!


The issue was as stated in comments above, I was not dismissing the keyboard from the ALERTDIALOG, I was working on the false assumption that when the dialog was dismissed that the keyboard would be as well. This assumption was wrong.

The keyboard for the alert dialog was not dismissed, the view returned to the parent view and because the edit text in the parent view got focus the keyboard updated itself to appear properly for this view.

The attempts to dismiss keyboard in the dialog dismiss listener did not remove the keyboard because they were trying to dismiss the keyboard for fields in the parent window and at the time of their execution it was still tied to the field in the alertview.

Add the dismisskeyboard calls to the onclick events that dismissed the dialout for the edittext fields in the alertDialog resolve the problem.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜