public void addTab(int index, TabInfo tabInfo) {
    if (tabInfo == null) {
      return;
    }

    View page = tabInfo.getPage();
    View item = tabInfo.getItem();

    item.setOnClickListener(onSelectorClickListener);
    if (page instanceof Pageable) {
      Pageable pageable = (Pageable) page;
      pageable.onInit(this);
    }

    if (index < 0 || index >= adapter.getCount()) {
      ViewGroup.LayoutParams itemParams = tabInfo.getItemParams();
      if (itemParams == null) {
        itemBar.addView(item);
      } else {
        itemBar.addView(item, itemParams);
      }
      adapter.add(page);
    } else {
      ViewGroup.LayoutParams itemParams = tabInfo.getItemParams();
      if (itemParams == null) {
        itemBar.addView(item, index);
      } else {
        itemBar.addView(item, index, itemParams);
      }
      adapter.add(index, page);
    }

    tabs.add(new Pair<View, View>(item, page));

    onGlobalLayout();
  }