Android TabWidget


  1. roolandb

    roolandb New Member

    I'm creating android application and I encountered a problem with tabs. They are working as they should, but in one of my tabs there are a button that leads to another class and it opens a whole new window and the tabs disappear, but I want it to open with the tabs staying at the top of my screen. Any suggestions?
    This is my tab code:
    Code (Text):
    1. package team.revo2;
    2.  
    3. import team.revo2.WorkoutsActivity;
    4. import team.revo2.ProgressActivity;
    5. import team.revo2.TimerActivity;
    6. import team.revo2.CalendarActivity;
    7. import android.app.TabActivity;
    8. import android.content.Intent;
    9. import android.content.res.Resources;
    10. import android.os.Bundle;
    11. import android.widget.TabHost;
    12.  
    13.  
    14. public class MyMenu extends TabActivity {
    15.  
    16.     @Override
    17.     protected void onCreate(Bundle savedInstanceState) {
    18.         // TODO Auto-generated method stub
    19.         super.onCreate(savedInstanceState);
    20.         setContentView(R.layout.main);
    21.        
    22. //      Resources res = getResources();
    23.         TabHost tabHost = getTabHost();
    24.         TabHost.TabSpec spec;      
    25.         Intent intent;
    26.        
    27.         intent = new Intent().setClass(this, WorkoutsActivity.class);
    28.         spec = tabHost
    29.                 .newTabSpec("workouts")
    30.                 .setIndicator("Workouts" , null)
    31.                 .setContent(intent);
    32.         tabHost.addTab(spec);
    33.        
    34.         intent = new Intent().setClass(this, ProgressActivity.class);
    35.         spec = tabHost
    36.                 .newTabSpec("progress")
    37.                 .setIndicator("Progress" , null)
    38.                 .setContent(intent);
    39.         tabHost.addTab(spec);
    40.  
    41.         intent = new Intent().setClass(this, TimerActivity.class);
    42.         spec = tabHost
    43.                 .newTabSpec("timer")
    44.                 .setIndicator("Timer" , null)
    45.                 .setContent(intent);
    46.         tabHost.addTab(spec);
    47.        
    48.         intent = new Intent().setClass(this, CalendarActivity.class);
    49.         spec = tabHost
    50.                 .newTabSpec("calendar")
    51.                 .setIndicator("Calendar" , null)
    52.                 .setContent(intent);
    53.         tabHost.addTab(spec);
    54.         tabHost.setCurrentTab(2);
    55.     }
    56. }

    Advertisement

Share This Page