Note that there are some explanatory texts on larger screens.

plurals
  1. POSoftKeyboard does not display for a newly displayed Fragment
    text
    copied!<p>I have a FragmentActivity that initially displays a fragment with a few buttons on it. When you click one of the buttons, the FragmentActivity displays a new fragment with some editText fields. I can't seem to get the soft input keyboard to display when my new fragment with the editText fields is displayed. </p> <p>Using the windowSoftInput mode on the manifest is out as that displays the keyboard right away.</p> <pre><code> android:windowSoftInputMode="stateUnchanged" </code></pre> <p>I have tried using </p> <p><code>getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE)</code></p> <p>to no avail. Here's how I display the new fragment from my Activity:</p> <pre><code>public void clickHandler(View view) { switch (view.getId()) { case R.id.login: loginFragment = new LoginFragment(); FragmentTransaction transaction = getSupportFragmentManager() .beginTransaction(); transaction.replace(R.id.fragment_container, loginFragment); transaction.addToBackStack(null); transaction.commit(); getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); break; </code></pre> <p>...</p> <p>I have also tried calling setSoftInputMode from within the fragment's onCreate and that has not worked as well. Thinking it was a timing issue I tried it with handler.postDelayed and that didn't work either. It looked like this:</p> <pre><code>onResume... Handler handler = new Handler(); Runnable runnable = new Runnable() { @Override public void run() { getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); } }; handler.postDelayed(runnable, 1000); </code></pre> <p>Any help will be appreciated. Thanks. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload