0

I have a simple DialogFragment that contains an EditText. When the DialogFragment is created the soft keyboard is shown immediately and the EditText gains immediate focus by using:

    mEditText.requestFocus();
    getDialog().getWindow().setSoftInputMode(
            LayoutParams.SOFT_INPUT_STATE_VISIBLE);

In fact, what I have is essentially like the example given in this blog:

http://android-developers.blogspot.co.uk/2012/05/using-dialogfragments.html

When the back button is pressed, I wish for the DialogFragment to be dismissed. What actually happens is that the first back button press causes the soft keyboard to be hidden. A further back press is required to dismiss the DialogFragment.

I was quite surprised that there doesn't seem to be a simple API solution for this (such as setting a flag) as I'd have thought it'd be a common requirement.

Having searched on SO the best option seems to be to detect when the soft keyboard has been hidden, and then call dismiss() on that event. Such possible solutions for detecting the soft keyboard is hidden are:

EditText with soft keyboard and "Back" button

How to check visibility of software keyboard in Android?

Before I go ahead and use one of the above solutions, is there any other means I should consider dismiss of the entire DialogFragment and soft keyboard with one hit of the back button?

Community
  • 1
  • 1
Trevor
  • 10,903
  • 5
  • 61
  • 84

1 Answers1

0

Why not using a cancel button instead of exploiting the back one?

sthor69
  • 638
  • 1
  • 10
  • 25