I had a similar problem with the soft keyboard; though in my case it would not show even without switching views with setContentView. After some experimenting I've found the solution which still works for me. The idea was to intercept soft keyboard showing/hiding for any EditText descendant. For this I overrode onWindowFocusChanged of the Activity.
The trick was in hiding the keyboard when it is not needed anymore.
As you can see I used toggleSoftInput with SHOW_IMPLICIT instead of any HIDE constant. In this case IMEManager would retain the keyboard visible only if the focused view requires it otherwise it will be hidden.
private boolean softInputActive;
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
InputMethodManager IMEManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
View focusedView = getCurrentFocus();
// Find the primitive focused view (not ViewGroup)
while (focusedView instanceof ViewGroup) {
focusedView = ((ViewGroup) focusedView).getFocusedChild();
}
if (hasFocus) {
if (focusedView instanceof EditText && focusedView.isEnabled()
&& !IMEManager.isActive(focusedView)) {
IMEManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
softInputActive = true;
}
} else if (softInputActive) {
if (focusedView != null && IMEManager.isActive()) {
IMEManager.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, 0);
}
softInputActive = false;
}
}