@Override public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) { Object tag = tab.getTag(); for (int i = 0; i < mTabs.size(); i++) { if (mTabs.get(i) == tag) { mViewPager.setCurrentItem(i); } } }
@Override public Fragment getItem(int i) { if (tabsDisabled) { return savedFragment; } else { ActionBar.Tab tab = actionBar.getTabAt(i); TiUIActionBarTab tabView = (TiUIActionBarTab) tab.getTag(); if (tabView.fragment == null) { tabView.initializeFragment(); } return tabView.fragment; } }
public void disableTabNavigation(boolean disable) { if (disable && actionBar.getNavigationMode() == ActionBar.NAVIGATION_MODE_TABS) { savedSwipeable = swipeable; swipeable = false; ActionBar.Tab tab = actionBar.getSelectedTab(); if (tab == null) { Log.e(TAG, "No selected tab when trying to disable Tab Navigation"); return; } TiUIActionBarTab tabView = (TiUIActionBarTab) tab.getTag(); savedFragment = tabView.fragment; tabsDisabled = true; tabGroupPagerAdapter.notifyDataSetChanged(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); } else if (!disable && actionBar.getNavigationMode() == ActionBar.NAVIGATION_MODE_STANDARD) { tabsDisabled = false; savedFragment = null; actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); tabGroupPagerAdapter.notifyDataSetChanged(); swipeable = savedSwipeable; } }
@Override public TabProxy getSelectedTab() { ActionBar.Tab tab; try { tab = actionBar.getSelectedTab(); } catch (NullPointerException e) { // This is a workaround for AppCompat actionbar 4.0+. There is a bug in AppCompat source that // will cause a null pointer exception if no tab is selected instead of returning null. See // source at: // https://android.googlesource.com/platform/frameworks/support/+/89208232f3b5d1451408d787872504a190bc7ee0/v7/appcompat/src/android/support/v7/app/ActionBarImplICS.java // line 259. tab = null; } if (tab == null) { // There is no selected tab currently for this action bar. // This probably means the tab group contains no tabs. return null; } TiUIActionBarTab tabView = (TiUIActionBarTab) tab.getTag(); return (TabProxy) tabView.getProxy(); }