2

I looks like Android FragmentTabHost is poorly documented, so I am trying to understand basic things in this question.

1 Regarding code snippet: http://developer.android.com/reference/android/support/v4/app/FragmentTabHost.html

    import com.example.android.supportv4.R;

    import android.os.Bundle;
    import android.support.v4.app.FragmentActivity;
    import android.support.v4.app.FragmentTabHost;

    /**
     * This demonstrates how you can implement switching between the tabs of a
     * TabHost through fragments, using FragmentTabHost.
     */
    public class FragmentTabs extends FragmentActivity {
        private FragmentTabHost mTabHost;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);

            setContentView(R.layout.fragment_tabs);
            mTabHost = (FragmentTabHost)findViewById(android.R.id.tabhost);
            mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);

            mTabHost.addTab(mTabHost.newTabSpec("simple").setIndicator("Simple"),
                FragmentStackSupport.CountingFragment.class, null);
            mTabHost.addTab(mTabHost.newTabSpec("contacts").setIndicator("Contacts"),
                LoaderCursorSupport.CursorLoaderListFragment.class, null);
            mTabHost.addTab(mTabHost.newTabSpec("custom").setIndicator("Custom"),
                LoaderCustomSupport.AppListFragment.class, null);
            mTabHost.addTab(mTabHost.newTabSpec("throttle").setIndicator("Throttle"),
                LoaderThrottleSupport.ThrottledLoaderListFragment.class, null);
        }
    }

1.1 It shows the programmatic approach to adding tabs. Can I define avoid it? Can I just define everything in XML: number of tabs, their labels, their contents (links to fragment layouts also defined in XML)? If not why, because it looks like a hack to define application layout partially via static XML, programmatically (although the definition it is also static by its nature)?

1.2 Does this snippet imply any XML layout file? Is there an official example for it?

1.3 Supposing that this snippet DOES imply an XML layout file: what is realtabcontent and tabcontent? Should I have both? Why? It looks like some sort of hack again.

2 Here is an unofficial example of using FragmentTabHost http://maxalley.wordpress.com/2013/05/18/android-creating-a-tab-layout-with-fragmenttabhost-and-fragments/

2.1 Why LinearLayout should be put inside android.support.v4.app.FragmentTabHost? Is there an official documentation explaining that?

2.2 Why LinearLayout contains only one FrameLayout, not two like here Android FragmentTabHost - Not fully baked yet? ? Why we do not need @+id/realtabcontent and @android:id/tabs ?

Community
  • 1
  • 1
Dmitry Mugtasimov
  • 3,858
  • 2
  • 18
  • 26

0 Answers0