package exp.tableHost;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.util.Log;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
public class HelloTabWidget extends TabActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Resources res = getResources(); // Resource object to get Drawables
TabHost tabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Resusable TabSpec for each tab
Intent intent; // Reusable Intent for each tab
// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this, AddActivity.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("add").setIndicator("添加",
res.getDrawable(R.drawable.add))
.setContent(intent);
tabHost.addTab(spec);
// Do the same for the other tabs
intent = new Intent().setClass(this, QueryActivity.class);
spec = tabHost.newTabSpec("query").setIndicator("查询",
res.getDrawable(R.drawable.query))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, CalculateActivity.class);
spec = tabHost.newTabSpec("calculate").setIndicator("计算",
res.getDrawable(R.drawable.calculate))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, SetActivity.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("about").setIndicator("关于",
res.getDrawable(R.drawable.about))
.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(2);
//处理tabId
tabHost.setOnTabChangedListener(new OnTabChangeListener() {
public void onTabChanged(String tabId) {
Log.i("HelloTabWidget", tabId) ;
}
});
}
}