EDIT : Seems I\'m not making myself clear. What I need is a way to hide the soft keyboard whenever i replace the fragment I am in. How do I go about doing this ?
I had the same issue and placed the following code in my tab fragment just prior to using the FragmentTransaction.replace()
method to change tabs. The onCreate
and onCreateView
methods in each fragment are not triggered after the initial tab selection, so hiding the keyboard can be done before getting to the specific fragment's class. Using mTabHost.getApplicationWindowToken()
rather than editText.getWindowToken()
was a major help. Thanks to whoever found that. Sorry I lost the link.
InputMethodManager im = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
im.hideSoftInputFromWindow(mTabHost.getApplicationWindowToken(), 0);
.......
fm = getFragmentManager();
....
fm.beginTransaction()
.replace(placeholder, new someFragment(), tabId)
.commit();