My ActionBar tabs are disappearing when I start an activity from them. I can see the Activity all right, but the tabs don’t appear.
My SherlockFragmentActivity is –
public class FragmentDemoActivity extends SherlockFragmentActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActionBar bar = getSupportActionBar();
bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
ActionBar.Tab tab1 = bar.newTab();
ActionBar.Tab tab2 = bar.newTab();
tab1.setText("Fragment A");
tab2.setText("Fragment B");
tab1.setTabListener(new MyTabListener());
tab2.setTabListener(new MyTabListener());
bar.addTab(tab1);
bar.addTab(tab2);
}
private class MyTabListener implements ActionBar.TabListener
{
@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
if(tab.getPosition()==0)
{
CalendarViewActivity frag = new CalendarViewActivity();
startActivity(new Intent(getApplicationContext(),CalendarViewActivity.class));
//ft.replace(android.R.id.content, frag);
}
else
{
TestActivity frag = new TestActivity();
//ft.replace(android.R.id.content, frag);
}
}
@Override
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
// TODO Auto-generated method stub
}
@Override
public void onTabReselected(Tab tab, FragmentTransaction ft) {
// TODO Auto-generated method stub
}
}
}
While my Acitivity is a normal Android Activity –
public class CalendarViewActivity extends Activity
Any help please.
while my
Of course not. You did not put any tabs on
CalendarViewActivity, in part becauseCalendarViewActivityis just a regularActivity.If you are thinking that tapping on a tab should load something into
FragmentDemoActivity, then you should not be callingstartActivity()from yourTabListener. Instead, you should be executing aFragmentTransactionor otherwise modifying the UI ofFragmentDemoActivity.