Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Did not tested it, but should be something like this</p> <pre><code>TabFragment extends SherlockFragment { TabHost mTabHost; TabManager mTabManager; mTabHost = (TabHost)findViewById(android.R.id.tabhost); mTabHost.setup(); mTabManager = new TabManager(this.getActivity(), mTabHost, R.id.realtabcontent); mTabManager.addTab(mTabHost.newTabSpec("first").setIndicator("First", getResources().getDrawable(R.drawable.ic_tab_first_tab)), FirstFragment.class , null); mTabManager.addTab(mTabHost.newTabSpec("second").setIndicator("Second", getResources().getDrawable(R.drawable.ic_tab_second_tab)), SecondFragment.class , null); public static class TabManager implements TabHost.OnTabChangeListener { private final FragmentActivity mActivity; private final TabHost mTabHost; private final int mContainerId; private final HashMap&lt;String, TabInfo&gt; mTabs = new HashMap&lt;String, TabInfo&gt;(); TabInfo mLastTab; 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; } } static class DummyTabFactory implements TabHost.TabContentFactory { private final Context mContext; public DummyTabFactory(Context context) { mContext = context; } public View createTabContent(String tag) { View v = new View(mContext); v.setMinimumWidth(0); v.setMinimumHeight(0); return v; } } public TabManager(FragmentActivity activity, TabHost tabHost, int containerId) { mActivity = activity; mTabHost = tabHost; mContainerId = containerId; mTabHost.setOnTabChangedListener(this); } 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.commitAllowingStateLoss(); } mTabs.put(tag, info); mTabHost.addTab(tabSpec); } 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.commitAllowingStateLoss(); mActivity.getSupportFragmentManager().executePendingTransactions(); } } } } </code></pre> <p>And your frament layout</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" &gt; &lt;TabHost android:id="@android:id/tabhost" android:layout_width="fill_parent" android:layout_height="fill_parent" &gt; &lt;LinearLayout android:orientation="vertical" android:layout_height="fill_parent" android:layout_width="fill_parent"&gt; &lt;FrameLayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_weight="1" android:layout_height="wrap_content"&gt; &lt;FrameLayout android:id="@+id/realtabcontent" android:layout_width="fill_parent" android:layout_height="fill_parent"/&gt; &lt;/FrameLayout&gt; &lt;TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_marginBottom="-4dp" android:background="#333333" android:layout_height="wrap_content" /&gt; &lt;/LinearLayout&gt; &lt;/TabHost&gt; &lt;/LinearLayout&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

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