public boolean removeTab(int index) {
    if (index < 0 || index >= tabs.size()) {
      return false;
    }

    Pair<View, View> tab = tabs.remove(index);
    if (tab != null) {
      itemBar.removeView(tab.first);
      adapter.remove(adapter.getIndexOfItem(tab.second));
      if (selector != null) {
        selector.remove(index);
      }
      onGlobalLayout();
      return true;
    }
    return false;
  }