/** * @brief Method called when the tab is selected * @param tab * @param ft * @details Method called when the tab is selected */ @Override public void onTabSelected(Tab tab, FragmentTransaction ft) { // Check if the fragment is already initialized mFragment = mActivity.getFragmentManager().findFragmentByTag(mTag); mActivity.getSupportFragmentManager().findFragmentByTag(mTag); if (mFragment == null) { // If not, instantiate and add it to the activity mFragment = Fragment.instantiate( mActivity, mClass.getName()); //mFragment.setProviderId(mTag); // id for event provider setmTransaction(ft); ft.add(android.R.id.content, mFragment, mTag); } else { // If it exists, simply attach it in order to show it setmTransaction(ft); ft.attach(mFragment); } }
/** * @brief Method called when the tab is unselected * @param tab * @param ft * @details Method called when the tab is unselected */ @Override public void onTabUnselected(Tab tab, FragmentTransaction ft) { if (mFragment != null) { // Detach the fragment, because another one is being attached ft.detach(mFragment); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // this.setContentView(R.layout.layout_main); ActionBar actionBar = getActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); actionBar.setDisplayShowTitleEnabled(true); Tab customerTab = actionBar.newTab().setText( this.getResources().getString(R.string.customer_tab)); final Fragment customerPackageList = new CustomerPackageFragment(this); customerTab.setTabListener(new PackageTabListener(customerPackageList)); Tab systemTab = actionBar.newTab().setText( this.getResources().getString(R.string.system_tab)); final Fragment systemPackageList = new SystemPackageFragment(this); systemTab.setTabListener(new PackageTabListener(systemPackageList)); actionBar.addTab(customerTab); actionBar.addTab(systemTab); }
@Override public void onTabSelected(final Tab tab, final FragmentTransaction ft) { if (fragment == null) { fragment = Fragment.instantiate(MainActivity.this, clazz.getName()); ft.replace(R.id.fragment_container, fragment, clazz.getSimpleName()); } else if (fragment.isDetached()) { ft.attach(fragment); } currentFragment = fragment; if (searchView != null) { searchView.setOnQueryTextListener(null); searchView.setQuery(null, false); searchView.setOnQueryTextListener(createSearchQueryListener()); } }
@Override public void onTabSelected(Tab tab, FragmentTransaction ft) { Fragment fragment = null; /*if (tab.getPosition() == 0) { fragment = new AlertsFragment(); } else if (tab.getPosition() == 1) { fragment = new ConditionsFragment(); } else if (tab.getPosition() == 2) { fragment = new ForecastFragment(); }*/ if (tab.getPosition() == 0) { fragment = new ConditionsFragment(); } else if (tab.getPosition() == 1) { fragment = new ForecastFragment(); } if (fragment != null) { mCurrentFragment = fragment; getFragmentManager().beginTransaction().replace(R.id.content_frame, fragment).commit(); } }
public void onTabSelected(Tab tab, FragmentTransaction ft) { int tabSelected = tab.getPosition(); Log.d(TAG, "Tab selected " + tabSelected + " current act " + currentActivityNo); if (canNavigateTo(tabSelected)){ viewPager.setCurrentItem(tabSelected); currentActivityNo = tabSelected; this.stopReading(); WidgetFactory currentWidget = (WidgetFactory) apAdapter.getItem(currentActivityNo); currentWidget.resetTimeTracking(); } else{ Runnable setPreviousTab = new Runnable(){ @Override public void run() { UIUtils.showAlert(CourseActivity.this, R.string.sequencing_dialog_title, R.string.sequencing_section_message); actionBar.setSelectedNavigationItem(currentActivityNo); viewPager.setCurrentItem(currentActivityNo); } }; Handler handler=new Handler(); handler.post(setPreviousTab); } }
@Override protected void onResume() { super.onResume(); // Select proper stack ActionBar actionBar = getActionBar(); if (actionBar != null) { Tab tab = actionBar.getSelectedTab(); Stack<String> backStack = backStacks.get(tab.getTag()); if (!backStack.isEmpty()) { // Restore topmost fragment (e.g. after application switch) String tag = backStack.peek(); Fragment fragment = getFragmentManager().findFragmentByTag(tag); if (fragment.isDetached()) { FragmentTransaction ft = getFragmentManager().beginTransaction(); ft.attach(fragment); ft.commit(); } } } }
@Override protected void onPause() { super.onPause(); // Select proper stack ActionBar actionBar = getActionBar(); if (actionBar != null) { Tab tab = actionBar.getSelectedTab(); Stack<String> backStack = backStacks.get(tab.getTag()); if (!backStack.isEmpty()) { // Detach topmost fragment otherwise it will not be correctly // displayed // after orientation change String tag = backStack.peek(); FragmentTransaction ft = getFragmentManager().beginTransaction(); Fragment fragment = getFragmentManager().findFragmentByTag(tag); ft.detach(fragment); ft.commit(); } } }
@Override public void onTabReselected(Tab tab, FragmentTransaction ft) { // Select proper stack Stack<String> backStack = backStacks.get(tab.getTag()); if (backStack.size() > 1) { // ft.setCustomAnimations(R.anim.slide_from_right, // R.anim.slide_to_left); // Clean the stack leaving only initial fragment while (backStack.size() > 1) { // Pop topmost fragment String tag = backStack.pop(); Fragment fragment = getFragmentManager().findFragmentByTag(tag); // Remove it ft.remove(fragment); } } showFragment(backStack, ft); }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); // Select proper stack ActionBar actionBar = getActionBar(); if (actionBar != null) { Tab tab = actionBar.getSelectedTab(); Stack<String> backStack = backStacks.get(tab.getTag()); Fragment fragment = getFragmentManager().findFragmentByTag(backStack.peek()); // Passing the Activity Result for the child fragment if (fragment != null) { fragment.onActivityResult(requestCode, resultCode, data); } } }
public void addFragment(Fragment fragment) { // Select proper stack ActionBar actionBar = getActionBar(); if (actionBar != null) { Tab tab = actionBar.getSelectedTab(); Stack<String> backStack = backStacks.get(tab.getTag()); FragmentTransaction ft = getFragmentManager().beginTransaction(); // Get topmost fragment String tag = backStack.peek(); Fragment top = getFragmentManager().findFragmentByTag(tag); if (top != null) { ft.detach(top); } // Add new fragment addFragment(fragment, backStack, ft); ft.commit(); } }
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) { // do something on back. ActionBar actionBar = getActionBar(); if (actionBar != null) { Tab tabSelected = actionBar.getSelectedTab(); if (tabSelected.getText().equals(getString(R.string.tab__list))) { finish(); moveTaskToBack(true); } else { getActionBar().selectTab(actionBar.newTab().setTag(TabType.LIST).setText(R.string.tab__list).setTabListener(this)); } } } return super.onKeyDown(keyCode, event); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ActionBar ab = getActionBar(); ab.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); // Add tabs Tab tab = ab.newTab() .setText(R.string.agendas) .setTabListener(new CalendarMuteTabListener<>(this, TAG_TAB_CALENDARS, CalendarsFragment.class)); ab.addTab(tab); tab = ab.newTab() .setText(R.string.actions) .setTabListener(new CalendarMuteTabListener<>(this, TAG_TAB_ACTIONS, ActionsFragment.class)); ab.addTab(tab); if(ACTION_SHOW_ACTIONS.equals(getIntent().getAction())) ab.setSelectedNavigationItem(1); // Show actions tab if(savedInstanceState != null && savedInstanceState.containsKey(KEY_SAVED_CURRENT_TAB)) ab.setSelectedNavigationItem(savedInstanceState.getInt(KEY_SAVED_CURRENT_TAB)); // Start service MuteService.startIfNecessary(this); }
public void addTab(Tab tab, Class<?> clss, Event event){ TabInfo info = new TabInfo(clss, event); tab.setTag(info); tab.setTabListener(this); mTabs.add(info); mFragments.add(EventFragment.newInstance(event)); mActionBar.addTab(tab); notifyDataSetChanged(); }
@Override public void onTabSelected(Tab tab, FragmentTransaction ft) { mViewPager.setCurrentItem(tab.getPosition()); Object tag = tab.getTag(); for (int i = 0; i<mTabs.size(); i++){ if (mTabs.get(i) == tag){ mViewPager.setCurrentItem(i); } } }
public void onTabSelected(Tab tab, FragmentTransaction ft) { if (mFragment == null) { mFragment = Fragment.instantiate(mActivity, mClass.getName()); ft.add(android.R.id.content, mFragment, mTag); } else { ft.attach(mFragment); } }
public void addTab(ActionBar.Tab tab, Class<?> clss, Bundle args) { TabInfo info = new TabInfo(clss, args); tab.setTag(info); tab.setTabListener(this); mTabs.add(info); mActionBar.addTab(tab); notifyDataSetChanged(); }
@Override public void onTabSelected(Tab tab, FragmentTransaction ft) { Object tag = tab.getTag(); for (int i = 0; i < mTabs.size(); i++) { if (mTabs.get(i) == tag) { mViewPager.setCurrentItem(i); } } }
@Override public void onTabSelected(Tab tab, FragmentTransaction fragmentTransaction) { fragment = activity.getFragmentManager().findFragmentByTag(tag); if(fragment == null) { // Create fragment fragment = Fragment.instantiate(activity, fragmentClass.getName()); fragmentTransaction.add(android.R.id.content, fragment, tag); } else { // Reuse fragmentTransaction.attach(fragment); } }
@Override public void onBackPressed() { // Select proper stack ActionBar actionBar = getActionBar(); if (actionBar != null) { Tab tab = actionBar.getSelectedTab(); Stack<String> backStack = backStacks.get(tab.getTag()); // Remove a fragment from the stack String tag; hideKeyboard(); if (backStack.isEmpty()) { shouldDisplayHomeUp(false); // Let application finish // super.onBackPressed(); } else { // Show/hide ActionBar up button if (backStack.size() > 1) { shouldDisplayHomeUp(true); } else { shouldDisplayHomeUp(false); } if (!backStack.isEmpty()) { tag = backStack.pop(); FragmentTransaction ft = getFragmentManager().beginTransaction(); Fragment fragment = getFragmentManager().findFragmentByTag(tag); // Remove topmost fragment from back stack and forget it ft.remove(fragment); showFragment(backStack, ft); ft.commit(); } } } }
@Override public void onTabUnselected(Tab tab, FragmentTransaction ft) { // Select proper stack Stack<String> backStack = backStacks.get(tab.getTag()); // Get topmost fragment String tag = ""; if (!backStack.isEmpty()) { tag = backStack.peek(); Fragment fragment = getFragmentManager().findFragmentByTag(tag); // Detach it ft.detach(fragment); } }
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); } }
@Override public void onTabSelected(Tab tab, FragmentTransaction ft) { viewPager.setCurrentItem(tab.getPosition()); }
public void onTabSelected(Tab tab, FragmentTransaction ft) { }
public void onTabUnselected(Tab tab, FragmentTransaction ft) { }
public void onTabReselected(Tab tab, FragmentTransaction ft) { }
/** * @brief This is the onCreate method * @param savedInstanceState * @details The onCreate method adds an actionBar to the activity with two tabs (recent and favorites). * It also load the preferences file into the prefs attribute and sets the rememeberExit attribute. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.tab_host); final ActionBar actionBar = getActionBar(); actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE|ActionBar.DISPLAY_SHOW_HOME); final String recents = getString(R.string.recents); final String favorites = getString(R.string.favoritesTab); // add tabs Tab tab1 = actionBar.newTab() .setText(recents) .setTabListener(new TabListener<ListFragmentTab>( this, "tab1", ListFragmentTab.class)); actionBar.addTab(tab1); Tab tab2 = actionBar.newTab() .setText(favorites) .setTabListener(new TabListener<ListFragmentTabFav>( this, "tab2", ListFragmentTabFav.class)); actionBar.addTab(tab2); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); //accedemos a fichero preferencias (Configuration.getInstance()).setPrefs( getSharedPreferences("PreferencesFile",Context.MODE_PRIVATE)); (Configuration.getInstance()).readPrefs(); // Orientation Change Occurred if(savedInstanceState!=null){ int currentTabIndex = savedInstanceState.getInt("tab_index"); actionBar.setSelectedNavigationItem(currentTabIndex); } //nombre en la activity bar final String title = getString(R.string.connections); setTitle(title); }
@Override public void onTabReselected(Tab tab, FragmentTransaction ft) { }
@Override public void onTabSelected(Tab tab, FragmentTransaction ft) { // on tab selected // show respected fragment view viewPager.setCurrentItem(tab.getPosition()); }
@Override public void onTabUnselected(Tab tab, FragmentTransaction ft) { }
@Override public void onTabUnselected(Tab tab, FragmentTransaction ft) { return; }
@Override public void onTabSelected(Tab tab, FragmentTransaction ft) { mViewPager.setCurrentItem(tab.getPosition()); onTabChanged(); }