TabHost的使用(二):实现TabHost.TabContentFactory接口

实现TabHost.TabContentFactory接口,要实现

public View createTabContent(String text)

package com.example.androidtest;

import android.os.Bundle;
import android.app.TabActivity;
import android.widget.TabHost;
import android.widget.TextView;
import android.view.View;

public class MainActivity extends TabActivity implements TabHost.TabContentFactory {
   
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
     
       final TabHost tabHost = getTabHost();
       tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("tab1").setContent(this));
       tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator("tab2").setContent(this));
       tabHost.addTab(tabHost.newTabSpec("tab3").setIndicator("tab3").setContent(this));
    }
    
    
    public View createTabContent(String tag)
    {
    	final TextView tv = new TextView(this);
    	tv.setText("Content for tab with tag " + tag);
    	return tv;
    }
    
}


你可能感兴趣的:(android)