Closing soft keyboard after switching tabs in tabhost

I am currently trying to make my program minimize the soft keyboard when changing tabs. Unfortunately, I cannot find any of the methods provided by TabHost, or otherwise check when a tab is changed, or run a method on tab change. I also tried adding android: onClick = "hideKeyboard" where hideKeyboard is the method that closes the keyboard, but this method doesn't seem to do anything on tab changes. The code for hideKeyboard looks like this:

public void hideKeyboard()
{
    InputMethodManager imm = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE);
    imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
}

      

Were there any other methods I could try to detect tab changes? Or is my hideKeyboard () method wrong?

+3


source to share


1 answer


I think OnTabChangeListener is the best place to do such an operation. In your case, it would be something like this:



tabhost.setOnTabChangedListener(new OnTabChangeListener(){
    @Override
    public void onTabChanged(String tabId){
        hideKeyboard()
    }
})

      

+6


source







All Articles