Android Adding Tab inside Fragment

后端 未结 4 1353
挽巷
挽巷 2020-12-15 01:15

I am Trying to add a TabHost Inside a Fragment ...The Code is given bellow.Here inside the Fragment I am Trying to add TabHost to show two Tab

public class T         


        
4条回答
  •  一个人的身影
    2020-12-15 01:31

    import android.app.Fragment;
    import android.os.Bundle;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.AnalogClock;
    import android.widget.TabHost;
    
    public class TabFragment extends Fragment {
    
        private TabHost mTabHost;
        View rootView;
    
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            rootView = inflater.inflate(R.layout.tabinterview, container, false);
            mTabHost = (TabHost) rootView.findViewById(R.id.tabhost);
            mTabHost.setup();
            TabHost.TabSpec spec = mTabHost.newTabSpec("tag");
            spec.setIndicator("Android");
            spec.setContent(new TabHost.TabContentFactory() {
    
                @Override
                public View createTabContent(String tag) {
                    // TODO Auto-generated method stub
                    return (new AnalogClock(getActivity()));
                }
            });
            mTabHost.addTab(spec);
            spec = mTabHost.newTabSpec("tag1");
            spec.setIndicator("java");
            spec.setContent(new TabHost.TabContentFactory() {
    
                @Override
                public View createTabContent(String tag) {
                    // TODO Auto-generated method stub
                    return (new AnalogClock(getActivity()));
                }
            });
            mTabHost.addTab(spec);
            spec = mTabHost.newTabSpec("tag2");
            spec.setIndicator("Favourate");
            spec.setContent(new TabHost.TabContentFactory() {
    
                @Override
                public View createTabContent(String tag) {
                    // TODO Auto-generated method stub
                    return (new AnalogClock(getActivity()));
                }
            });
            mTabHost.addTab(spec);
            return rootView;
        }
    }
    
    this code how to give Page Link
    

提交回复
热议问题