Im new to Android and Java development and am following the Tab Layout tutorial on the Android Dev site. Ive run into a problem with the code. Just using some copy-pasta magic to make sure I have no misspellings, Ive inserted all the needed code for the tutorial. Problem is that the getTabHost() is undefined… Here is the code:
public class AHActivity extends Activity {
/** 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, EvoActivity.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("evolution").setIndicator("Evolution")
.setContent(intent);
tabHost.addTab(spec);
// Do the same for the other tabs
intent = new Intent().setClass(this, physActivity.class);
spec = tabHost.newTabSpec("physics").setIndicator("Physics")
.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(2);
}
}
Your activity should extend TabActivity not Activity.
Note: Tabactivitity deprecated in latest versions, consider learning Fragments