2

I have a Dialog in which I am having a EditText. Issues which I am facing are:

1). When Dialog is shown at that moment Keyboard does not come itself. So I had to programmatically bring keyboard up.

InputMethodManager immOnResume = (InputMethodManager) getActivity().getSystemService(
                                        Context.INPUT_METHOD_SERVICE);
                        immOnResume.showSoftInput(mEditText,
                                InputMethodManager.SHOW_FORCED);

2). When pressing home button keyboard is still visible in Home screen. I think as I am programmatically bringing keyboard up then I have to programmatically hide keyboard.

InputMethodManager immN = (InputMethodManager) getActivity().getSystemService(
                                    Context.INPUT_METHOD_SERVICE);
                    immN.hideSoftInputFromWindow(
                            mEditText.getWindowToken(), 0);

But these also isn't working. Any suggestions how can I solve my issue.

Vaibs
  • 1,128
  • 3
  • 16
  • 36
  • 2
    The keyboard is not disappearing because you used `InputMethodManager.SHOW_FORCED`. You should use `InputMethodManager.SHOW_IMPLICIT` instead. – Karakuri May 30 '13 at 16:43

3 Answers3

0

Try

getWindow().setSoftInputMode (WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
svennergr
  • 800
  • 1
  • 8
  • 26
0

You can use myedittext.requestFocus()

The keyboard will automatically vanish when activity is destroyed.

Adesh Atole
  • 766
  • 1
  • 8
  • 22
0

If your UI is written in XML, you might consider adding the requestFocus tag:

<EditText ...>
    <requestFocus />
</EditText>

That should trigger the focus on your EditText field when your dialog opens, which in turn should open your keyboard.

If, however, your UI is done programatically

editText.requestFocus()
Matt
  • 186
  • 5