Following is the example of tabs with intent data.
While debugging i found that always when first tab we add in tab host in our case following tab
tabHost.addTab(tabHost.newTabSpec("tab1")
.setIndicator("list")
.setContent(new Intent(this, List1.class)));
oncreate method of "List1" intent get called regardless it is our current tab or not even if if i define tab2 as a current tab how to fix this ?
public class Tabs3 extends TabActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final TabHost tabHost = getTabHost();
tabHost.addTab(tabHost.newTabSpec("tab1")
.setIndicator("list")
.setContent(new Intent(this, List1.class)));
tabHost.addTab(tabHost.newTabSpec("tab2")
.setIndicator("photo list")
.setContent(new Intent(this, List8.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)));
// This tab sets the intent flag so that it is recreated each time
// the tab is clicked.
tabHost.addTab(tabHost.newTabSpec("tab3")
.setIndicator("destroy")
.setContent(new Intent(this, Controls2.class)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)));
}
}
setDefaultTab(1);
seems not to be working in TabActivity when separate Activities are used as Tab Content.
Use following instead of this method,
tabHost.setCurrentTab(1);
This will set "photo list" (i.e second tab) as the selected or default tab...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With