Ejemplo n.º 1
0
  public void setCurrentTab(int index) {
    if (index < 0 || index >= mTabSpecs.size()) {
      return;
    }

    if (index == mCurrentTab) {
      return;
    }

    // notify old tab content
    if (mCurrentTab != -1) {
      mTabSpecs.get(mCurrentTab).mContentStrategy.tabClosed();
    }

    mCurrentTab = index;
    final TabHost.TabSpec spec = mTabSpecs.get(index);

    // Call the tab widget's focusCurrentTab(), instead of just
    // selecting the tab.
    mTabWidget.focusCurrentTab(mCurrentTab);

    // tab content
    mCurrentView = spec.mContentStrategy.getContentView();

    if (mCurrentView.getParent() == null) {
      mTabContent.addView(
          mCurrentView,
          new ViewGroup.LayoutParams(
              ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));
    }

    if (!mTabWidget.hasFocus()) {
      // if the tab widget didn't take focus (likely because we're in touch mode)
      // give the current tab content view a shot
      mCurrentView.requestFocus();
    }

    // mTabContent.requestFocus(View.FOCUS_FORWARD);
    invokeOnTabChangeListener();
  }