- publicclass BaniTabbedScreen extends TabActivity implements OnTabChangeListener {
- private TabHost tabHost;
- @Override
- publicvoid onCreate(Bundle savedInstanceState){
- super.onCreate(savedInstanceState);
- setContentView(R.layout.tabbed_screen);
- /* TabHost will have Tabs */
- tabHost =(TabHost) findViewById(android.R.id.tabhost);
- tabHost.setOnTabChangedListener(this);
- /* TabSpec used to create a new tab.
- * By using TabSpec only we can able to setContent to the .
- * By using TabSpec setIndicator() we can set name to tab. */
- /* tid1 is firstTabSpec Id. Its used to access outside. */
- TabSpec audioTabSpec = tabHost.newTabSpec("audio");
- TabSpec videoTabSpec = tabHost.newTabSpec("video");
- /* TabSpec setIndicator() is used to set name for the tab. */
- * TabSpec setContent() is used to set content for a particular tab. */
- audioTabSpec.setIndicator("Audio", getResources().getDrawable(R.drawable.audio));
- videoTabSpec.setIndicator("Video", getResources().getDrawable(R.drawable.video));
- TextView audioContent =new TextView(this);
- audioContent.setText("Listen to Gurbani Audio");
- audioTabSpec.setContent(audioContent.getId());
- TextView videoContent =new TextView(this);
- videoContent.setText("Watch the Gurbani Video");
- videoTabSpec.setContent(videoContent.getId());
- /* Add tabSpec to the TabHost to display. */
- tabHost.addTab(audioTabSpec);
- tabHost.addTab(videoTabSpec);
- }
- }
↧
How to create a Tabbed Screen in Android?
↧