Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can check here: <a href="http://developer.android.com/reference/android/app/TabActivity.html" rel="noreferrer">http://developer.android.com/reference/android/app/TabActivity.html</a></p> <p>In that example they show how to use the FragmentTabs with the support package, if you look down you can see that they implement their own TabManager class. There they implement the function addTab: </p> <pre><code> public void addTab(TabHost.TabSpec tabSpec, Class&lt;?&gt; clss, Bundle args) { tabSpec.setContent(new DummyTabFactory(mActivity)); String tag = tabSpec.getTag(); 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 &amp;&amp; !info.fragment.isDetached()) { FragmentTransaction ft = mActivity.getSupportFragmentManager().beginTransaction(); ft.detach(info.fragment); ft.commit(); } mTabs.put(tag, info); mTabHost.addTab(tabSpec); } </code></pre> <p>There you create the object TabInfo, previously defined as:</p> <pre><code> static final class TabInfo { private final String tag; private final Class&lt;?&gt; clss; private final Bundle args; private Fragment fragment; TabInfo(String _tag, Class&lt;?&gt; _class, Bundle _args) { tag = _tag; clss = _class; args = _args; } } </code></pre> <p>you can put data on that bundle (args). Now if you look at the overridden function onTabChanged you can see how the bundle is passed on the instantiation of the fragment(newTab.args):</p> <pre><code> @Override 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(); } } </code></pre> <p>Finally you can access that bundle from the fragment itself calling getArguments ()</p> <p>hope that helps.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload