zoukankan      html  css  js  c++  java
  • FragmentTabHost

    FragmentTabHost

    public class FragmentTabHost  extends TabHost implements TabHost.OnTabChangeListener

    java.lang.Object
       ↳ android.view.View
         ↳ android.view.ViewGroup
           ↳ android.widget.FrameLayout
             ↳ android.widget.TabHost
               ↳

    android.support.v4.app.FragmentTabHost

     Special TabHost that allows the use of Fragment objects for its tab content. When placing this in a view hierarchy, after inflating the hierarchy you must call setup(Context, FragmentManager, int) to complete the initialization of the tab host.

    example

    Here is a simple example of using a FragmentTabHost in an Activity:

    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);
        }
    }
    

     This can also be used inside of a fragment through fragment nesting:

    import com.example.android.supportv4.R;
    
    import android.os.Bundle;
    import android.support.v4.app.Fragment;
    import android.support.v4.app.FragmentTabHost;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    
    public class FragmentTabsFragmentSupport extends Fragment {
        private FragmentTabHost mTabHost;
    
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            mTabHost = new FragmentTabHost(getActivity());
            mTabHost.setup(getActivity(), getChildFragmentManager(), R.id.fragment1);
    
            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);
    
            return mTabHost;
        }
    
        @Override
        public void onDestroyView() {
            super.onDestroyView();
            mTabHost = null;
        }
    }
    
  • 相关阅读:
    ios代码大全
    MYSQL数据库之如何在已经建立好表之后重构数据表
    关于cookie在一个页面设置但是在另外一个页面获取不到的原因
    cookie的那点事儿
    关于a标签不能调用js方法的小细节,你注意到了么?
    关于mysql预处理技术的一点小心得
    关于delete使用limit的一些注意事项
    DP1 等分连续1-N个数的划分种数
    Spring 编程式事务和声明式事务管理
    java https client信任所有证书
  • 原文地址:https://www.cnblogs.com/mbp-study/p/5643809.html
Copyright © 2011-2022 走看看