
Untitled
By: a guest on
May 1st, 2012 | syntax:
None | size: 1.14 KB | hits: 28 | expires: Never
Android: getTabHost() Error
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);
}
}
public class AHActivity extends TabActivity {