Code example for TabHost

Methods: addTabnewTabSpecsetOnTabChangedListenersetup

0
	/** 
	 * Initialise the Tab Host 
	 */ 
	private void initialiseTabHost(Bundle args) {
		mTabHost = (TabHost)findViewById(android.R.id.tabhost);
        mTabHost.setup();
        TabInfo tabInfo = null;
        TabsViewPagerFragmentActivity.AddTab(this, this.mTabHost, this.mTabHost.newTabSpec("Tab1").setIndicator("Tab 1"), ( tabInfo = new TabInfo("Tab1", Tab1Fragment.class, args)));
        this.mapTabInfo.put(tabInfo.tag, tabInfo);
        TabsViewPagerFragmentActivity.AddTab(this, this.mTabHost, this.mTabHost.newTabSpec("Tab2").setIndicator("Tab 2"), ( tabInfo = new TabInfo("Tab2", Tab2Fragment.class, args)));
        this.mapTabInfo.put(tabInfo.tag, tabInfo);
        TabsViewPagerFragmentActivity.AddTab(this, this.mTabHost, this.mTabHost.newTabSpec("Tab3").setIndicator("Tab 3"), ( tabInfo = new TabInfo("Tab3", Tab3Fragment.class, args)));
        this.mapTabInfo.put(tabInfo.tag, tabInfo);
        // Default to first tab 
        //this.onTabChanged("Tab1"); 
        // 
        mTabHost.setOnTabChangedListener(this);
	} 
	 
	/** 
	 * Add Tab content to the Tabhost 
	 * @param activity 
	 * @param tabHost 
	 * @param tabSpec 
	 * @param clss 
	 * @param args 
	 */ 
	private static void AddTab(TabsViewPagerFragmentActivity activity, TabHost tabHost, TabHost.TabSpec tabSpec, TabInfo tabInfo) {
		// Attach a Tab view factory to the spec 
		tabSpec.setContent(activity.new TabFactory(activity));
        tabHost.addTab(tabSpec);
	} 
 
	/** (non-Javadoc) 
	 * @see android.widget.TabHost.OnTabChangeListener#onTabChanged(java.lang.String) 
	 */