This code works well for displaying separate xml items in my main.xml. But is there any way to run an activity in each tab? Preferably without extending TabActivity, because its deprecated. Or should i use a completely different approach?
Thanks
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TabHost tabs = (TabHost)findViewById(R.id.TabHost01);
tabs.setup();
TabHost.TabSpec spec1 = tabs.newTabSpec("tag1");
spec1.setContent(R.id.AnalogClock01);
spec1.setIndicator("Analog Clock");
tabs.addTab(spec1);
TabHost.TabSpec spec2 = tabs.newTabSpec("tag2");
spec2.setContent(R.id.DigitalClock01);
spec2.setIndicator("Digital Clock");
tabs.addTab(spec2);
}
Yes, you should use
Fragments. There is some sample code in the API Demos that demonstrates the approach (calledFragmentTabs.java) but you’ll most likely want to read up onFragments before you start, since they were a very important introduction to Android 3.0 and are included in the compatibility package that goes back to Android 1.6.