In Androd_Tab_view.java file, I have the following code :
tabs = (TabHost)findViewById(R.id.TabHost1);
tabs.setup();
TabHost.TabSpec first_tab = tabs.newTabSpec("tag1");
first_tab.setContent(new Intent(this,FirstTab.class));
first_tab.setIndicator("Book");
tabs.addTab(first_tab);
//SecondTab.class
TabHost.TabSpec second_tab = tabs.newTabSpec("tag2");
second_tab.setContent(new Intent(this,SecondTab.class));
second_tab.setIndicator("Authors");
tabs.addTab(second_tab);
In FirstTab.java file I have the following code :
public class FirstTab extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/* First Tab Content */
TextView textView = new TextView(this);
textView.setText("First Tab");
setContentView(textView);
}
}
In SecondTab.java file I have the following code :
public class SecondTab extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState); /* Second Tab Content */
TextView textView = new TextView(this);
textView.setText("Second Tab");
setContentView(textView);
}
}
But when I try to run this code I get an exception . What can be possible solution for this problem ??
You create Tab like this
and your Activities are
and
and tis http://www.androidhive.info/2011/08/android-tab-layout-tutorial/