@Override
    public void onTabSelected(Tab tab, FragmentTransaction ft) {
      if (mFragment == null) {
        mFragment = Fragment.instantiate(mActivity, mClass.getName(), mArgs);
        ft.add(android.R.id.content, mFragment, mTag);
      } else {
        ft.attach(mFragment);
      }

      if (mFragment instanceof GotoDirectFragment) {
        ((GotoDirectFragment) mFragment).onTabSelected();
      } else {
        InputMethodManager imm =
            (InputMethodManager) mActivity.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(
            mActivity.findViewById(android.R.id.content).getWindowToken(),
            InputMethodManager.HIDE_IMPLICIT_ONLY);
      }
    }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    bookId = getIntent().getIntExtra(EXTRA_bookId, -1);
    chapter_1 = getIntent().getIntExtra(EXTRA_chapter, 0);
    verse_1 = getIntent().getIntExtra(EXTRA_verse, 0);

    ActionBar actionBar = getSupportActionBar();

    if (getResources().getBoolean(R.bool.screen_sw_check_min_600dp) == false) {
      // The following two options trigger the collapsing of the main action bar view.
      actionBar.setDisplayShowHomeEnabled(false);
      actionBar.setDisplayShowTitleEnabled(false);
    }

    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    actionBar.addTab(
        actionBar
            .newTab()
            .setTag(tab_dialer)
            .setText(R.string.goto_tab_dialer_label)
            .setTabListener(
                new TabListener<GotoDialerFragment>(
                    this,
                    "dialer",
                    GotoDialerFragment.class,
                    GotoDialerFragment.createArgs(bookId, chapter_1, verse_1)))); // $NON-NLS-1$
    actionBar.addTab(
        actionBar
            .newTab()
            .setTag(tab_direct)
            .setText(R.string.goto_tab_direct_label)
            .setTabListener(
                new TabListener<GotoDirectFragment>(
                    this,
                    "direct",
                    GotoDirectFragment.class,
                    GotoDirectFragment.createArgs(bookId, chapter_1, verse_1)))); // $NON-NLS-1$
    actionBar.addTab(
        actionBar
            .newTab()
            .setTag(tab_grid)
            .setText(R.string.goto_tab_grid_label)
            .setTabListener(
                new TabListener<GotoGridFragment>(
                    this,
                    "grid",
                    GotoGridFragment.class,
                    GotoGridFragment.createArgs(bookId, chapter_1, verse_1)))); // $NON-NLS-1$

    if (savedInstanceState == null) {
      // get from preferences
      int tabUsed = Preferences.getInt(Prefkey.goto_last_tab, 0);
      if (tabUsed >= 1 && tabUsed <= 3) {
        actionBar.setSelectedNavigationItem(tabUsed - 1 /* to make it 0-based */);
      }
    } else {
      actionBar.setSelectedNavigationItem(savedInstanceState.getInt(INSTANCE_STATE_tab, 0));
    }
  }
 @Override
 public void onTabReselected(Tab tab, FragmentTransaction ft) {
   if (mFragment instanceof GotoDirectFragment) {
     ((GotoDirectFragment) mFragment).onTabSelected();
   }
 }