Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6853213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:29:06+00:00 2026-05-27T01:29:06+00:00

I checked up some online tutorials on how to build a TAB in android

  • 0

I checked up some online tutorials on how to build a TAB in android and saw a tutorial that fit my requirements. I was happy to implement it and it worked well. The problem came when I wanted each separate tab to push to one separate activity. I couldn’t start and intent to pass on the control. I’ve given only the main code as to how I am making the Tab’s as the xml required for the construction does not have any functionality in this question.

Here is the code:

public class Secondactivity extends TabActivity {
private TabHost mTabHost;
private void setupTabHost() {
mTabHost = (TabHost) findViewById(android.R.id.tabhost);
mTabHost.setup();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
setupTabHost();
    mTabHost.getTabWidget().setDividerDrawable(se.copernicus.activity.R.drawable.tab_divider);

    setupTab(new TextView(this), "Month");
    setupTab(new TextView(this), "Week");
    setupTab(new TextView(this), "Day");
}
private void setupTab(final View view, final String tag) {
View tabview = createTabView(mTabHost.getContext(), tag);

TabSpec setContent = mTabHost.newTabSpec(tag).setIndicator(tabview)
        .setContent(new TabContentFactory() {
            public View createTabContent(String tag) {
                return view;
            }
        });
mTabHost.addTab(setContent);

}

private static View createTabView(final Context context, final String text) {
View view = LayoutInflater.from(context)
        .inflate(R.layout.tabs_bg, null);
TextView tv = (TextView) view.findViewById(R.id.tabsText);
tv.setText(text);
return view;
   }
}

How can I start a new Intent so that when the Tab is clicked it should go from Secondactivity to WeekActivity or DayActivity ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T01:29:07+00:00Added an answer on May 27, 2026 at 1:29 am
    public class MainTabActivity extends TabActivity
    
    {
        private TabHost mTabHost;
    
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.program_guide_tab_activity_layout);
    
        mTabHost = (TabHost) findViewById(android.R.id.tabhost);
        setupTab(new TextView(this), getString(R.string.live));
        setupTab(new TextView(this), getString(R.string.guide));
        setupTab(new TextView(this), getString(R.string.remotes));
        setupTab(new TextView(this), getString(R.string.settings));
    
        mTabHost.setCurrentTabByTag(getString(R.string.live));
    }
    
    private void setupTab(final View view, final String tag)
    {
        View tabview = createTabView(mTabHost.getContext(), tag);
    
        if (tag.compareTo(getString(R.string.live)) == 0)
        {
            Intent intent = new Intent(getApplicationContext(), LiveActivity.class);
    
            TabSpec setContent = mTabHost.newTabSpec(getString(R.string.live)).setIndicator(tabview).setContent(new TabHost.TabContentFactory()
            {
    
                public View createTabContent(String tag)
                {
                    return view;
                }
    
            });
    
            setContent.setContent(intent);
            mTabHost.addTab(setContent);
        }
    
        if (tag.compareTo(getString(R.string.guide)) == 0)
        {
            Intent intent = new Intent(getApplicationContext(), ProgramGuide.class);
    
            TabSpec setContent = mTabHost.newTabSpec(getString(R.string.guide)).setIndicator(tabview).setContent(new TabHost.TabContentFactory()
            {
    
                public View createTabContent(String tag)
                {
                    return view;
                }
    
            });
    
            setContent.setContent(intent);
            mTabHost.addTab(setContent);
        }
    
        if (tag.compareTo(getString(R.string.remotes)) == 0)
        {
            Intent intent = new Intent(getApplicationContext(), RemoteMultiPanel.class);
    
            TabSpec setContent = mTabHost.newTabSpec(getString(R.string.remotes)).setIndicator(tabview).setContent(new TabHost.TabContentFactory()
            {
    
                public View createTabContent(String tag)
                {
                    return view;
                }
    
            });
    
            setContent.setContent(intent);
            mTabHost.addTab(setContent);
        }
    
        if (tag.compareTo(getString(R.string.settings)) == 0)
        {
            Intent intent = new Intent(getApplicationContext(), SettingsMain.class);
    
            TabSpec setContent = mTabHost.newTabSpec(getString(R.string.settings)).setIndicator(tabview).setContent(new TabHost.TabContentFactory()
            {
    
                public View createTabContent(String tag)
                {
                    return view;
                }
    
            });
    
            setContent.setContent(intent);
            mTabHost.addTab(setContent);
        }
    }
    
    private static View createTabView(final Context context, final String text)
    {
        View view = LayoutInflater.from(context).inflate(R.layout.tabs_bg, null);
        TextView tv = (TextView) view.findViewById(R.id.tabsText);
        tv.setText(text);
    
        int resId = 0;
        ImageView iconImageView = (ImageView) view.findViewById(R.id.imageView1);
    
        if (text.compareTo(context.getString(R.string.settings)) == 0)
        {
            resId = R.drawable.settings_icon;
        }
        else if (text.compareTo(context.getString(R.string.remotes)) == 0)
        {
            resId = R.drawable.remotes_icon;
        }
        else if (text.compareTo(context.getString(R.string.live)) == 0)
        {
            resId = R.drawable.live_icon;
        }
        else if (text.compareTo(context.getString(R.string.guide)) == 0)
        {
            resId = R.drawable.guide_icon;
        }
    
        iconImageView.setImageResource(resId);
    
        return view;
    }
    

    }

    check out the setupTap() method:
    it’s control the 4 possible intent’s that raised activities:
    LiveActivity, ProgramGuide, ….

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm practicing on Django and using some online tutorial to build a web blog.
After some use Visual Studio 2008 when opening a solution that is checked into
New to sencha touch here. I've checked out quite a few tutorials online. I
While attempting to build a website, i have gone through many online tutorials. Thanks
Ok, so at some point in time, somebody checked in some files with names
HTML: <a href=# rel=tooltip>Open Tooltip</a> <div id=tooltip>Tooltip Content</div> I checked out some tooltip plugins
One of my co-workers checked in a some files in SVN and one of
I have a ListView with multiple choice entries where some are checked from the
We had an employee leave the company, and they left some files checked out
When updating my checked out directory with TortoiseSVN, some subfolders are listed as Skipped

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.