@Override public void onTabChanged(String tabId) { TabInfo newTab = mTabs.get(tabId); if (mLastTab != newTab) { FragmentTransaction ft = mActivity.getFragmentManager().beginTransaction(); if (mLastTab != null) { if (mLastTab.fragment != null) { ft.hide(mLastTab.fragment); } } if (newTab != null) { if (newTab.fragment == null) { newTab.fragment = Fragment.instantiate(mActivity, newTab.clss.getName(), newTab.args); ft.add(mContainerId, newTab.fragment, newTab.tag); // Log.i(LOG_TAG, "onTabChanged with tabId:" + tabId // + ", newTab.fragment is null, newTab.tag is " // + newTab.tag); } else { ft.show(newTab.fragment); // Log.i(LOG_TAG, "onTabChanged with tabId:" + tabId // + ", show fragment success"); } } else { // Log.i(LOG_TAG, "onTabChanged with tabId:" + tabId // + ", newTab is null"); } mLastTab = newTab; ft.commit(); mActivity.getFragmentManager().executePendingTransactions(); } mActivity.onTabChanged(tabId); }
@Override public void onCheckedChanged(RadioGroup group, int checkedId) { TabInfo newTab = mTabs.get("" + checkedId); if (mLastTab != newTab) { FragmentTransaction ft = mFragmentManager.beginTransaction(); if (mLastTab != null) { if (mLastTab.fragment != null) { ft.detach(mLastTab.fragment); } } if (newTab != null) { if (newTab.fragment == null) { newTab.fragment = (BaseFragment) Fragment.instantiate(group.getContext(), newTab.clss.getName(), newTab.args); ft.add(mContainerId, newTab.fragment, newTab.tag); } else { ft.attach(newTab.fragment); } } mLastTab = newTab; ft.commit(); mFragmentManager.executePendingTransactions(); } }
public Fragment getItem(int position) { TabInfo info = mTabs.get(position); if (info.fragment == null) { info.fragment = Fragment.instantiate(mContext, info.clss.getName(), info.args); } return info.fragment; }
@Override public Object instantiateItem(ViewGroup container, int position) { TabInfo tab = tabs.get(position); BaseFragment fragment = (BaseFragment) super.instantiateItem(container, position); tab.fragment = fragment; return fragment; }
private FragmentTransaction doTabChanged(String tabId, FragmentTransaction ft) { TabInfo newTab = null; for (int i = 0; i < mTabs.size(); i++) { TabInfo tab = mTabs.get(i); if (tab.tag.equals(tabId)) { newTab = tab; } } if (newTab == null) { throw new IllegalStateException("No tab known for tag " + tabId); } if (mLastTab != newTab) { if (ft == null) { ft = mFragmentManager.beginTransaction(); } if (mLastTab != null) { if (mLastTab.fragment != null) { // ft.detach(mLastTab.fragment); ft.hide(mLastTab.fragment); } } if (newTab != null) { if (newTab.fragment == null) { newTab.fragment = Fragment.instantiate(mContext, newTab.clss.getName(), newTab.args); ft.add(mContainerId, newTab.fragment, newTab.tag); } else { // ft.attach(newTab.fragment); ft.show(newTab.fragment); } } mLastTab = newTab; } return ft; }
@Override public Fragment getItem(int position) { TabInfo info = mTabInfos.get(position); if (info.fragment == null) info.fragment = Fragment.instantiate(mActivity, info._clss.getName(), info._args); return info.fragment; }
@Override public Object instantiateItem(ViewGroup container, int position) { final Fragment fragment = (Fragment) super.instantiateItem(container, position); final TabInfo info = mTabs.get(position); info.tag = fragment.getTag(); // set it here info.fragment = fragment; return fragment; }
@Override public android.support.v4.app.Fragment getItem(int position) { TabInfo info = mTabs.get(position); if (info.fragment == null) { info.fragment = android.support.v4.app.Fragment.instantiate(mContext, info.clss.getName(), info.args); } return info.fragment; }
public void addTab(int radioButtonId, Class<?> clss, String tag, Bundle args) { String tabId = "" + radioButtonId; TabInfo info = new TabInfo(tag, clss, args); info.fragment = (BaseFragment) mFragmentManager.findFragmentByTag(tag); if (info.fragment != null && !info.fragment.isDetached()) { FragmentTransaction ft = mFragmentManager.beginTransaction(); ft.detach(info.fragment); ft.commit(); } mTabs.put(tabId, info); }
/** * Ajout d'une tab au conteneur * * @param activity activit� concern�e * @param tabHost Hote des Tabs * @param tabSpec nouvelle spec de la tab * @param tabInfo infos de la � cr�er */ private static void addTab( DiffusionTabActivity activity, TabHost tabHost, TabHost.TabSpec tabSpec, TabInfo tabInfo) { // On Attache une factory � la spec de la tab tabSpec.setContent(activity.new TabFactory(activity)); String tag = tabSpec.getTag(); // On v�rifie si un fragment est d�j� li� � cette spec au quel cas // on le d�sactive afin de garantir l'�tat initial cach� tabInfo.fragment = activity.getSupportFragmentManager().findFragmentByTag(tag); if (tabInfo.fragment != null && !tabInfo.fragment.isDetached()) { FragmentTransaction ft = activity.getSupportFragmentManager().beginTransaction(); ft.detach(tabInfo.fragment); ft.commit(); activity.getSupportFragmentManager().executePendingTransactions(); } tabHost.addTab(tabSpec); }
public void addTab(final TabHost.TabSpec tabSpec, final Class<?> clss, final Bundle args) { tabSpec.setContent(new DummyTabFactory(mActivity)); final String tag = tabSpec.getTag(); final TabInfo info = new TabInfo(tag, clss, args); // Check to see if we already have a fragment for this tab, probably // from a previously saved state. If so, deactivate it, because our // initial state is that a tab isn't shown. info.fragment = mActivity.getSupportFragmentManager().findFragmentByTag(tag); if (info.fragment != null && !info.fragment.isDetached()) { final FragmentTransaction ft = mActivity.getSupportFragmentManager().beginTransaction(); ft.detach(info.fragment); ft.commit(); } mTabs.put(tag, info); mTabHost.addTab(tabSpec); }
public void addTab(TabHost.TabSpec tabSpec, Class<?> clss, Bundle args) { tabSpec.setContent(new DummyTabFactory(mContext)); String tag = tabSpec.getTag(); TabInfo info = new TabInfo(tag, clss, args); if (mAttached) { // If we are already attached to the window, then check to make // sure this tab's fragment is inactive if it exists. This shouldn't // normally happen. info.fragment = mFragmentManager.findFragmentByTag(tag); if (info.fragment != null && !info.fragment.isDetached()) { FragmentTransaction ft = mFragmentManager.beginTransaction(); ft.detach(info.fragment); ft.commit(); } } mTabs.add(info); addTab(tabSpec); }
@Override protected void onAttachedToWindow() { super.onAttachedToWindow(); String currentTab = getCurrentTabTag(); // Go through all tabs and make sure their fragments match // the correct state. FragmentTransaction ft = null; for (int i = 0; i < mTabs.size(); i++) { TabInfo tab = mTabs.get(i); tab.fragment = mFragmentManager.findFragmentByTag(tab.tag); // if (tab.fragment != null && !tab.fragment.isDetached()) { if (tab.fragment != null) { if (tab.tag.equals(currentTab)) { // The fragment for this tab is already there and // active, and it is what we really want to have // as the current tab. Nothing to do. mLastTab = tab; } else { // This fragment was restored in the active state, // but is not the current tab. Deactivate it. if (ft == null) { ft = mFragmentManager.beginTransaction(); } // ft.detach(tab.fragment); ft.hide(tab.fragment); } } } // We are now ready to go. Make sure we are switched to the // correct tab. mAttached = true; ft = doTabChanged(currentTab, ft); if (ft != null) { ft.commit(); mFragmentManager.executePendingTransactions(); } }
public void onTabChanged(String tabId) { TabInfo newTab = mTabs.get(tabId); if (mLastTab != newTab) { FragmentTransaction ft = mActivity.getSupportFragmentManager().beginTransaction(); if (mLastTab != null) { if (mLastTab.fragment != null) { ft.detach(mLastTab.fragment); } } if (newTab != null) { if (newTab.fragment == null) { newTab.fragment = Fragment.instantiate(mActivity, newTab.clss.getName(), newTab.args); ft.add(mContainerId, newTab.fragment, newTab.tag); } else { ft.attach(newTab.fragment); } } mLastTab = newTab; ft.commit(); mActivity.getSupportFragmentManager().executePendingTransactions(); } }
/** * Changement de Tabs * * @see android.widget.TabHost.OnTabChangeListener#onTabChanged(java.lang.String) */ public void onTabChanged(String tag) { TabInfo newTab = (TabInfo) this.mapTabInfo.get(tag); if (mLastTab != newTab) { FragmentTransaction ft = this.getSupportFragmentManager().beginTransaction(); if (mLastTab != null) { if (mLastTab.fragment != null) { ft.detach(mLastTab.fragment); } } if (newTab != null) { if (newTab.fragment == null) { newTab.fragment = Fragment.instantiate(this, newTab.clss.getName(), newTab.args); ft.add(R.id.realtabcontent, newTab.fragment, newTab.tag); } else { ft.attach(newTab.fragment); } } mLastTab = newTab; ft.commit(); this.getSupportFragmentManager().executePendingTransactions(); } }
@Override public void onTabChanged(String tag) { AppMain.isShelf = false; if (AppMain.isphone) { TabInfo newTab = mapTabInfo.get(tag); if (mLastTab != newTab) { FragmentTransaction ft = this.getSupportFragmentManager().beginTransaction(); // pause if (mLastTab != null) { if (mLastTab.fragment != null) { ft.detach(mLastTab.fragment); } if (mLastTab.tag.equals("Tab1")) { if (Fragment_Ebook.isChoice) { Fragment_Ebook.isChoice = false; Adapter_List_Ebook_MasterDetail.phoneToDetail = false; Fragment_Ebook.sCatIDs = ""; Fragment_Ebook.bCode = ""; } if (getSupportFragmentManager().getBackStackEntryCount() > 0) { getSupportFragmentManager().popBackStack(); } if (Fragment_Ebook.fragment_ebook != null) { if (Fragment_Ebook.fragment_ebook.HaveFragment) { if (Fragment_Ebook.fragment_ebook.frag_search != null) { ft.detach(Fragment_Ebook.fragment_ebook.frag_search); } } } } if (mLastTab.tag.equals("Tab2")) { if (Fragment_Publisher.fragment_Publisher != null) { if (Fragment_Publisher.fragment_Publisher.HaveFragment) { if (Fragment_Publisher.fragment_Publisher.frag_searchpublisher != null) { ft.detach(Fragment_Publisher.fragment_Publisher.frag_searchpublisher); } } } } } // resume if (newTab != null) { if (newTab.tag.equals("Tab1")) { if (Fragment_Ebook.fragment_ebook != null) { if (Fragment_Ebook.fragment_ebook.HaveFragment) { if (Fragment_Ebook.fragment_ebook.frag_search != null) { ft.attach(Fragment_Ebook.fragment_ebook.frag_search); } mLastTab = newTab; ft.commit(); this.getSupportFragmentManager().executePendingTransactions(); return; } } } if (newTab.tag.equals("Tab2")) { if (Fragment_Publisher.fragment_Publisher != null) { if (Fragment_Publisher.fragment_Publisher.HaveFragment) { if (Fragment_Publisher.fragment_Publisher.frag_searchpublisher != null) { ft.attach(Fragment_Publisher.fragment_Publisher.frag_searchpublisher); } mLastTab = newTab; ft.commit(); this.getSupportFragmentManager().executePendingTransactions(); return; } } } if (newTab.fragment == null) { newTab.fragment = Fragment.instantiate(this, newTab.clss.getName(), newTab.args); ft.add(R.id.realtabcontent, newTab.fragment, newTab.tag); } else { ft.attach(newTab.fragment); } } mLastTab = newTab; ft.commit(); this.getSupportFragmentManager().executePendingTransactions(); } } else { if (Fragment_Ebook.isTabletChoose) { Fragment_Ebook.isTabletChoose = false; Adapter_List_Ebook_MasterDetail.phoneToDetail = false; Fragment_Ebook.sCatIDs = ""; Fragment_Ebook.bCode = ""; } if (getSupportFragmentManager().getBackStackEntryCount() > 0) { getSupportFragmentManager().popBackStack(); } // tablet TabInfo newTab = mapTabInfo.get(tag); if (mLastTab != newTab) { FragmentTransaction ft = this.getSupportFragmentManager().beginTransaction(); // pause if (mLastTab != null) { if (mLastTab.fragment != null) { ft.detach(mLastTab.fragment); } } // resume if (newTab != null) { if (newTab.fragment == null) { newTab.fragment = Fragment.instantiate(this, newTab.clss.getName(), newTab.args); ft.add(R.id.realtabcontent, newTab.fragment, newTab.tag); } else { ft.attach(newTab.fragment); } } mLastTab = newTab; ft.commit(); this.getSupportFragmentManager().executePendingTransactions(); } } }
public void addTab(Fragment _fragment, String _title) { final TabInfo _tabInfo = new TabInfo(); _tabInfo.fragment = _fragment; _tabInfo.title = _title; tabs.add(_tabInfo); }